Forum Moderators: coopster

Message Too Old, No Replies

using unix timestamp with dates before 1970

convert mysql date function

         

pixeltierra

7:53 pm on Aug 23, 2006 (gmt 0)

10+ Year Member



I made the following function to convert mysql dates YYYY-MM-DD into a string like Jan 3, 1995. The problem is that for dates before 1970, it fails, because I can't get time stamp.

How do I format dates without a timestamp? What do I do?

function format_mysql_date ($mysql_date) {

list($y, $m, $d) = explode ('-', $mysql_date);

return date("M j, Y", mktime(0, 0, 0, $m, $d, $y));

}

mikesmith76

10:59 pm on Aug 23, 2006 (gmt 0)

10+ Year Member



there is a library for dealing with earlier dates, think it's called adodb_time

[phplens.com...]

this should help

coopster

1:16 pm on Aug 24, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Since the date is coming from MySQL you can also use MySQL's Date and Time Functions [dev.mysql.com].
SELECT DATE_FORMAT('1995-01-03', '%b %e, %Y');