I have the following variable which contains mysql timestamp value.
var dateReceived='2014-11-07 16:21:50'
Please help me to change the time in 12 O'clock(AM/PM) format using jQuery.
Asked
Active
Viewed 3,239 times
1

Saharsh Shah
- 28,687
- 8
- 48
- 83

Subhajyoti De
- 47
- 1
- 2
- 9
-
refer this link http://stackoverflow.com/questions/23946698/changing-date-time-format-using-jquery-javascript – Sush Dec 09 '14 at 11:35
2 Answers
1
Use DATE_FORMAT() function to convert the format of date
Try this:
SELECT DATE_FORMAT('2014-11-07 16:21:50', '%Y-%m-%d %h:%i:%s %p')
OUTPUT
2014-11-07 04:21:50 PM

Saharsh Shah
- 28,687
- 8
- 48
- 83
0
this code might help you in your code.
var myDate = new Date('2014-11-07 16:21:50');
var ouputDate = myDate.toLocaleString();

Subhajyoti De
- 47
- 1
- 2
- 9

Ashwin
- 431
- 1
- 5
- 11
-
when i try to put my variable in the Date(),like `var myDate = new Date(dateReceived);` it is showing `invalid date`.I must put the variable (`dateReceived` ,which store the dynamic value fetched from database) in the Date(). – Subhajyoti De Dec 09 '14 at 11:59
-
it is because the data coming from mySQL in your variable is different from the format we have used here, it should be year-date-month hour:min:seconds or date-month-year hour:min: seconds – Ashwin Dec 09 '14 at 12:33