smc Posted January 27, 2007 Share Posted January 27, 2007 Hiya,Okay I've been googling for about 3 hours and have been at a loss for this.I have found the PHP.net entry on formatting the date using date() but my problem is I need it to format the date FROM the date(); function after it was inject into the db.ie. I need to format the date from my MySQL database into terms such as "January 26th, 2006 @ 7:53PM EST"How would I go about doing that? Link to comment https://forums.phpfreaks.com/topic/35900-solved-date-formatting/ Share on other sites More sharing options...
Jessica Posted January 27, 2007 Share Posted January 27, 2007 print date("F jS Y", strtotime($rowDate)); Link to comment https://forums.phpfreaks.com/topic/35900-solved-date-formatting/#findComment-170250 Share on other sites More sharing options...
smc Posted January 27, 2007 Author Share Posted January 27, 2007 Your the best jesiroseThanks! Link to comment https://forums.phpfreaks.com/topic/35900-solved-date-formatting/#findComment-170254 Share on other sites More sharing options...
smc Posted January 27, 2007 Author Share Posted January 27, 2007 The date formatting works great but I think I'm having trouble storing the date in the first place.Which function do I use to store the date in the Database?ie. $variabletostore = ??; Link to comment https://forums.phpfreaks.com/topic/35900-solved-date-formatting/#findComment-170368 Share on other sites More sharing options...
trq Posted January 27, 2007 Share Posted January 27, 2007 If you want to store the current time (when the insert happens) your best off to use mysql's NOW() function. eg;[code]INSERT INTO tbl (stamp) VALUES (NOW());[/code]Otherwise, take a look at the rest of mysql's date / time functions [url=http://mysql.org/doc/refman/5.0/en/date-and-time-functions.html]here[/url]. Link to comment https://forums.phpfreaks.com/topic/35900-solved-date-formatting/#findComment-170369 Share on other sites More sharing options...
smc Posted January 27, 2007 Author Share Posted January 27, 2007 Will the date function be able to format that time?EDIT: I answered that question through testing :pThanks!!! Link to comment https://forums.phpfreaks.com/topic/35900-solved-date-formatting/#findComment-170370 Share on other sites More sharing options...
Jessica Posted January 27, 2007 Share Posted January 27, 2007 The one I posted for you will, yes.If you need to format time from a timestamp into mysql datetime format, just use date();so say you want to put yesterday's date in the db.$yesterday = time()-(60*60*24);$str = date("Y-m-d H:i:s", $yesterday);$sql = "INSERT INTO table(yourDate) VALUES('$str')"; Link to comment https://forums.phpfreaks.com/topic/35900-solved-date-formatting/#findComment-170373 Share on other sites More sharing options...
smc Posted January 27, 2007 Author Share Posted January 27, 2007 For some reason date(); was generating an error so I just used the MySQL NOW() function to inject the time stamp directly into the DB and then call it using the date function you recommendend.Thanks for all your help :) Link to comment https://forums.phpfreaks.com/topic/35900-solved-date-formatting/#findComment-170498 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.