Problem formatting date a time
Posted: Thu Jun 05, 2003 11:42 am
I posted a thread similar to this a few days ago, and I appreciate the replies I received. However, I'm still not able to format a date field how I want.
I'm inserting dates into mysql with the format YYYY-MM-DD into a "date" field. I'm not using timestamps.
I browsed the mysql date and time functions page (http://www.mysql.com/doc/en/Date_and_ti ... ml#IDX1305)and came up with this non-working code:
$query = "SELECT DATE_FORMAT(MyDate, '%b %e, %Y'), TIME_FORMAT(MyTime, '%l:%i %p') FROM mytable;
This didn't work, so I though maybe it's because it's not in a timestamp format, so I tried this:
$query = "SELECT DATE_FORMAT(UNIX_TIMESTAMP(MyDate), '%b %e, %Y'), TIME_FORMAT(UNIX_TIMESTAMP(MyTime), '%l:%i %p') FROM mytable;
That doesn't work either. In my first post, I questioned whether or not dates were able to be formatted from a non-timestamp value. I really didn't get an answer to that. So, can someone please tell me if I'm wasting my time trying to format a mysql "date" field (YYYY-MM-DD).
I'm inserting dates into mysql with the format YYYY-MM-DD into a "date" field. I'm not using timestamps.
I browsed the mysql date and time functions page (http://www.mysql.com/doc/en/Date_and_ti ... ml#IDX1305)and came up with this non-working code:
$query = "SELECT DATE_FORMAT(MyDate, '%b %e, %Y'), TIME_FORMAT(MyTime, '%l:%i %p') FROM mytable;
This didn't work, so I though maybe it's because it's not in a timestamp format, so I tried this:
$query = "SELECT DATE_FORMAT(UNIX_TIMESTAMP(MyDate), '%b %e, %Y'), TIME_FORMAT(UNIX_TIMESTAMP(MyTime), '%l:%i %p') FROM mytable;
That doesn't work either. In my first post, I questioned whether or not dates were able to be formatted from a non-timestamp value. I really didn't get an answer to that. So, can someone please tell me if I'm wasting my time trying to format a mysql "date" field (YYYY-MM-DD).