Jump to content

[SOLVED] easy one if you know date()


Lodius2000

Recommended Posts

Hi i dont know jack about date(), do you?

 

if so please help,

 

I want to parse this time, from a datetime mysql field: 2008-01-25 19:50:00

 

i want it to say" 7:50 PM on Friday, January 25, 2008 "

 

i wouldnt mind if those days and months were abbreviated, either or

 

the date time is stored in

 

$row['date'] and is running in a foreach loop,

 

here is my stab at it

 

date('H:i A on D F j, Y', $row['timestamp'])

thanks for your help

and it prints out

 

19:33 PM 197012 Wed December 31, 1969

 

dont ask me where it is getting that date, but it is the same in each iteration of the foreach loop

 

 

Link to comment
https://forums.phpfreaks.com/topic/109350-solved-easy-one-if-you-know-date/
Share on other sites

made a couple mistakes above,

 

I got it to print out the date formattd how I like it but it is still printing the 1969 date with every iteration of the foreach loop

 

whats with that

 

new code

 

date('h:i A \o\n D. F j, Y.', $row['timestamp'])

 

thanks

Use the mysql date_format() function in your SELECT query to format a datetime field any way you want - http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format

 

The reason your existing code is not working is because the php date() function expects a Unix timestamp as the second parameter - http://php.net/date

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.