View Full Version : Standard Dates

12-18-2006, 06:11 PM
The last two days Ive been reading into the PHP FAQ to solve my problem with Dates, but I cant seem to find any info there or in the nettalk forums that resolve my problem. Basically I want to fetch the current date in this format Day, Month, Year and insert it into my DB then fetch the info later on and display it like Day, Month, Year. Up till now Ive used Unix Timestamps, but well I dont need the exact minute or hour for this project and the Unix Timestamp uses just that.

Ive used the Date function to get the date, but cant insert the Variable with the date into my database. The column type is currently set at Date.

Thanks for any help.

12-18-2006, 09:50 PM
The column type is currently set at Date.That might be the problem right there. Mysql is annoying about how it auto formats some things. Just change it to mediumtext, or something along those lines. (An int setting could work, but then it defaults to 0, and when you get that later, you get jan1, 1970, since that's what it represents as a unix timestamp.)

Just use time() to get the current timestamp (or date(), with no second parameter or input time), and display how you want. But always STORE the unix timestamp, and when you display it, be sure to do so as a date. It hurts nothing if you don't need the hour/min/sec. I did the same thing recently... it's fine.

So.... I'd suggest, for ease of use, making a function, so you can call the formatting easily.

function t2d($t) {
return date('M j, Y',$t);
//format the date as you want... that gives ex: Jan 1, 1999

///do whatever else you want, including html... etc. etc.

//later, call that function with t2d($time);....

echo t2d($time);