Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.