lalnfl Posted July 10, 2010 Share Posted July 10, 2010 I am have troubles displaying a date. I got the information from the database. Then I used the date() function. This is how it looks: $date = date('M j,Y' , $post_date); the $post_date is from the database query I defined it as $post_date = $row3['post_time']; In the database I am using datetime for the post_time field If you understand the mess I just said, do you know what I am doing wrong? And please show examples. I did echo it, but when I did, it display Dec 31, 1969. The day should be Jul 9, 2010 Quote Link to comment https://forums.phpfreaks.com/topic/207376-formatting-a-date-coming-from-a-database-table/ Share on other sites More sharing options...
myrddinwylt Posted July 10, 2010 Share Posted July 10, 2010 Hello, The datetime field stores the date and time as a string in the format "Y-m-d h:i:s A". As this is a string format, you can not format the date string without converting it back into a timestamp variable type. Try the following $post_date = strtotime($row3['post_time']); Quote Link to comment https://forums.phpfreaks.com/topic/207376-formatting-a-date-coming-from-a-database-table/#findComment-1084207 Share on other sites More sharing options...
.josh Posted July 10, 2010 Share Posted July 10, 2010 ...or just format it in your query so the result returned from the query is already formatted... Quote Link to comment https://forums.phpfreaks.com/topic/207376-formatting-a-date-coming-from-a-database-table/#findComment-1084223 Share on other sites More sharing options...
lalnfl Posted July 11, 2010 Author Share Posted July 11, 2010 myrddinwylt you are a life saver or at least a php saver. THANKS A BUNCH!!! Quote Link to comment https://forums.phpfreaks.com/topic/207376-formatting-a-date-coming-from-a-database-table/#findComment-1084288 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.