ashkey Posted August 19, 2008 Share Posted August 19, 2008 Hi there I am hoping that somebody will be able to help with this script I have had written. It uploads data from a .csv file to a database, although it works fine the problem is the seconds wont upload on the date and time. If I upload 16/08/2008 00:04:40 it shows on the database table as 2008-08-16 00:04:00. I need it to show the seconds also so it reads 2008-08-16 00:04:40. I have been trying for a few days but no luck can someone help? Thanks $dobParts = split("/", $AdobSTRING); $Adob = $dobParts[2]."-".$dobParts[1]."-".$dobParts[0]; $datetimeParts = split(" ", $AdatetimeSTRING); $dateParts = split("/", $datetimeParts[0]); $timeParts = split(":", $datetimeParts[1]); $Adatetime = $dateParts[2]."-".$dateParts[1]."-".$dateParts[0]." ".$timeParts[0].":".$timeParts[1].":00" ; Quote Link to comment https://forums.phpfreaks.com/topic/120331-can-somebody-help-with-this-script/ Share on other sites More sharing options...
Mchl Posted August 19, 2008 Share Posted August 19, 2008 There are specialised functions for parsing date and time. Try them http://pl.php.net/datetime Quote Link to comment https://forums.phpfreaks.com/topic/120331-can-somebody-help-with-this-script/#findComment-619947 Share on other sites More sharing options...
ashkey Posted August 19, 2008 Author Share Posted August 19, 2008 Thanks couldnt find the answer though, if anyone else knows please advise? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/120331-can-somebody-help-with-this-script/#findComment-619983 Share on other sites More sharing options...
JonnoTheDev Posted August 19, 2008 Share Posted August 19, 2008 You are adding the seconds in as 00 yourself: $Adatetime = $dateParts[2]."-".$dateParts[1]."-".$dateParts[0]." ".$timeParts[0].":".$timeParts[1].":00" ; Quote Link to comment https://forums.phpfreaks.com/topic/120331-can-somebody-help-with-this-script/#findComment-620012 Share on other sites More sharing options...
ashkey Posted August 19, 2008 Author Share Posted August 19, 2008 Hi Yes I should have said before, I realise that, if I remove the 00 the script wont import the data. I believe there should be another date part entered but I cant get it to work? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/120331-can-somebody-help-with-this-script/#findComment-620039 Share on other sites More sharing options...
revraz Posted August 19, 2008 Share Posted August 19, 2008 Its not in $timeParts[2] ? Quote Link to comment https://forums.phpfreaks.com/topic/120331-can-somebody-help-with-this-script/#findComment-620083 Share on other sites More sharing options...
ashkey Posted August 19, 2008 Author Share Posted August 19, 2008 I tried adding the .$timeParts[2] but this didn't work either, does anybody know the correct formula for this to work? $Adatetime = $dateParts[2]."-".$dateParts[1]."-".$dateParts[0]." ".$timeParts[0].":".$timeParts[1].":".$timeParts[2]; Your help would be much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/120331-can-somebody-help-with-this-script/#findComment-620129 Share on other sites More sharing options...
Mchl Posted August 19, 2008 Share Posted August 19, 2008 Why not: $datetime = "16/08/2008 00:04:40"; $datetime = str_replace("/","-",$datetime); $time = strtotime($datetime); echo date("Y-m-d H:i:s",$time); Quote Link to comment https://forums.phpfreaks.com/topic/120331-can-somebody-help-with-this-script/#findComment-620146 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.