Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any Javascript DateTime Function return MySQL datetime format?

I've a function that send ajax request to a server file with parameters. Problem is i want to send current DateTime value to compare it from database.

as MySQL datatime format all datetimes are shown as "2012-02-03 19:50:28" format.

How can i generate it in Javascript.

Another question: Can i add hours to current datetime (to fix server time zone problem)

Thanks in advance

like image 830
Erhan H. Avatar asked Dec 09 '22 02:12

Erhan H.


1 Answers

try this

/* use a function for the exact format desired... */
function ISODateString(d){
  function pad(n){return n<10 ? '0'+n : n}
  return d.getUTCFullYear()+'-'
      + pad(d.getUTCMonth()+1)+'-'
      + pad(d.getUTCDate()) +' '
      + pad(d.getUTCHours())+':'
      + pad(d.getUTCMinutes())+':'
      + pad(d.getUTCSeconds())
}

var d = new Date();
console.log(ISODateString(d)); // prints something like 2009-09-28 19:03:12

Refernece:
date format
date type in javascript
working with dates

like image 126
diEcho Avatar answered Jan 04 '23 23:01

diEcho