Αποτελέσματα Αναζήτησης
var pad = function(num) { return ('00'+num).slice(-2) }; var date; date = new Date(); date = date.getUTCFullYear() + '-' + pad(date.getUTCMonth() + 1) + '-' + pad(date.getUTCDate()) + ' ' + pad(date.getUTCHours()) + ':' + pad(date.getUTCMinutes()) + ':' + pad(date.getUTCSeconds());
If you are working with dates in more than one place, I suggest you use moment.js. You can then do something like moment(n).format('YYYY-MM-DD HH-mm-ss') to achieve what you wanted.
27 Νοε 2019 · You can easily solve the problem by using moment.js. require('moment')().format('YYYY-MM-DD HH:mm:ss'); If you don't want to go this route, you can also solve it without an additional library - it just doesn't read as nicely. const d = new Date(); d.toISOString().split('T')[0]+' '+d.toTimeString().split(' ')[0];
3 Απρ 2019 · We can combine the SQL DATEADD and CONVERT functions to get output in desired DateTime formats. Suppose, in the previous example; we want a date format in of MMM DD, YYYY. We can use the format code 107 to get output in this format.
To set a SQL date from JavaScript, you can use the following steps: Convert the JavaScript Date object to a string in the ISO 8601 format. This format is supported by all major SQL databases. Use the toISOString() method on the JavaScript Date object to convert it to a string in the ISO 8601 format. Replace the T character in the string with a ...
SQL Server comes with the following data types for storing a date or a date/time value in the database: DATE - format YYYY-MM-DD. DATETIME - format: YYYY-MM-DD HH:MI:SS. SMALLDATETIME - format: YYYY-MM-DD HH:MI:SS. TIMESTAMP - format: a unique number.
1 Απρ 2019 · set @vardate= SUBSTRING(@vardate, 1, 2)+'-'+ SUBSTRING(@vardate, 3, 2) +'-'+SUBSTRING(@vardate, 5, 4) select CONVERT(date, @vardate) as dataconverted. We use substring to concatenate the “-” to use an acceptable date format and then we use the CONVERT function to convert the characters to sql date.