Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
12-09-2008, 09:13 PM #1
- Join Date
- Sep 2008
- Thanked 1 Time in 1 Post
Converting a british date to a timestamp
At the moment I have some dates stored in my database as a string in british format (DD/MM/YYYY). I need to convert these dates into timestamps and then put them back into the database.
Converting them is easy enough using mktime() which turns this into a Unix Timestamp. Inserting that just puts in todays timestamp by default. I tried using the date() function to create a timestamp in mysql format (which I believe is YYYYMMDDhhmmss) but this didn't work either. If anybody could help me, that'd be awesome. Anyway, here's some of the code I was using to try and get this to work.
$date = explode("/",$articleResult['DateAdded']);
$newDate = mktime(0,0,0,$date,$date,$date);
$newDate2 = date("YmdHis", $newDate);
mysql_query("UPDATE new_article SET DateAdded2 = '".$newDate2."' WHERE ArticleID = '".$articleResult['ArticleID']."'");
12-09-2008, 10:02 PM #2
- Join Date
- Oct 2006
- Denver, Colorado USA
- Thanked 333 Times in 325 Posts
Use the mysql STR_TO_DATE() function directly in a single UPDATE query - http://dev.mysql.com/doc/refman/5.0/...on_str-to-date
There is no need to select the data, loop through it, convert it, and UPDATE the DateAdded2 column. Just UPDATE the DateAdded2 column directly.
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.