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? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 27, 2007 Share Posted January 27, 2007 print date("F jS Y", strtotime($rowDate)); Quote Link to comment Share on other sites More sharing options...
smc Posted January 27, 2007 Author Share Posted January 27, 2007 Your the best jesiroseThanks! Quote Link to comment 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 = ??; Quote Link to comment 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]. Quote Link to comment 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!!! Quote Link to comment 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')"; Quote Link to comment 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 :) Quote Link to comment 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.