sylunt1 Posted January 22, 2008 Share Posted January 22, 2008 Hello: I am having issues with the below script. It is not computing the date correctly and none of the other variables are getting passed to the db. The object is to take tse_start (entered as mm/dd/yyyy) and add 28 days to it - this new date is to be entered as tse_estlive. Any help is appreciated. <?PHP $tse_start = $_POST['tse_start']; $tse_id = $_POST['tse_id']; $tse_name = $_POST['tse_name']; $tse_mentorname = $_POST['tse_mentorname']; $tse_mgr = $_POST['tse_mgr']; $tse_grpid = $_POST['tse_grpid']; $tse_start = $_POST['tse_start']; $tse_level = $_POST['tse_level']; $tse_weekorder = $_POST['tse_weekorder']; $tse_bootdone = $_POST['tse_bootdone']; $tse_start_db = date('Y-m-d', strtotime($tse_start)); $tse_est_live_db = date('Y-m-d', strtotime('$tse_start_db +28 days')); $db = mysql_connect("$server", "$user", "$password"); mysql_select_db('mentor', $db) or die ('Cannot connect to $db_Database : ' . mysql_error()); echo "$tse_start_db"; echo "$tse_name $tse_mentorname $tse_mgr $tse_grpid $tse_start_db $tse_estlive_db $tse_level $tse_weekorder $tse_bootdone"; $sql = "INSERT INTO tse (tse_name, tse_mentorname, tse_mgr, tse_grpid, tse_start, tse_estlive, tse_level, tse_weekorder, tse_bootdone) VALUES ('$tse_name', '$tse_mentorname', '$tse_mgr', '$tse_grpid', '$tse_start', '$tse_est_live_db', '$tse_level', '$tse_weekorder', '$tse_bootdone')"; $sql_result = mysql_query($sql,$db) or die ('Could not insert data'); echo('Data inserted successfully.'); mysql_close($db); Quote Link to comment https://forums.phpfreaks.com/topic/87230-date-strtotime-question/ Share on other sites More sharing options...
p2grace Posted January 22, 2008 Share Posted January 22, 2008 Here's an alternative way of doing it. $tse_start = "01/12/2008"; $tse_start_db = explode("/",$tse_start); $tse_start_db = $tse_start_db[2]."-".$tse_start_db[0]."-".$tse_start_db[1]; $tse_start_db_live = $tse_start_db[2]."-".$tse_start_db[0]."-".($tse_start_db[1] + 28); Quote Link to comment https://forums.phpfreaks.com/topic/87230-date-strtotime-question/#findComment-446222 Share on other sites More sharing options...
sylunt1 Posted January 22, 2008 Author Share Posted January 22, 2008 That just prints out -- nothing else.... Quote Link to comment https://forums.phpfreaks.com/topic/87230-date-strtotime-question/#findComment-446235 Share on other sites More sharing options...
p2grace Posted January 22, 2008 Share Posted January 22, 2008 Did you replace these two lines of yours: $tse_start_db = date('Y-m-d', strtotime($tse_start)); $tse_est_live_db = date('Y-m-d', strtotime('$tse_start_db +28 days')); with these lines of mine? //$tse_start = "01/12/2008"; $tse_start_db = explode("/",$tse_start); $tse_start_db = $tse_start_db[2]."-".$tse_start_db[0]."-".$tse_start_db[1]; $tse_start_db_live = $tse_start_db[2]."-".$tse_start_db[0]."-".($tse_start_db[1] + 28); What I gave you was just an alternative to using strtotime Quote Link to comment https://forums.phpfreaks.com/topic/87230-date-strtotime-question/#findComment-446239 Share on other sites More sharing options...
obsidian Posted January 22, 2008 Share Posted January 22, 2008 The issue is that you are using single quotes around your string, so your variable is never being parsed before calculation. Change this line: <?php $tse_est_live_db = date('Y-m-d', strtotime('$tse_start_db +28 days')); ?> To this: <?php $tse_est_live_db = date('Y-m-d', strtotime("$tse_start_db +28 days")); // or this... $tse_est_live_db = date('Y-m-d', strtotime($tse_start_db . ' +28 days')); ?> Quote Link to comment https://forums.phpfreaks.com/topic/87230-date-strtotime-question/#findComment-446253 Share on other sites More sharing options...
sylunt1 Posted January 22, 2008 Author Share Posted January 22, 2008 p2grace - yes i replaced my lines with yours... no go... obsidian - originally mine was using " and not ' - still same issue. I tried the 2nd example and still nothin... It is really perplexing... Quote Link to comment https://forums.phpfreaks.com/topic/87230-date-strtotime-question/#findComment-446291 Share on other sites More sharing options...
p2grace Posted January 22, 2008 Share Posted January 22, 2008 When you say it's a no go, what is it doing? Quote Link to comment https://forums.phpfreaks.com/topic/87230-date-strtotime-question/#findComment-446292 Share on other sites More sharing options...
obsidian Posted January 22, 2008 Share Posted January 22, 2008 p2grace - yes i replaced my lines with yours... no go... obsidian - originally mine was using " and not ' - still same issue. I tried the 2nd example and still nothin... It is really perplexing... Yes, what exactly is it doing? I see you are building your entire script off the assumption that $_POST['tse_start']... have you tried echoing that variable out to make sure that it carries what you think it does? Quote Link to comment https://forums.phpfreaks.com/topic/87230-date-strtotime-question/#findComment-446322 Share on other sites More sharing options...
sylunt1 Posted January 22, 2008 Author Share Posted January 22, 2008 it isnt echoing anything out - once I put the date modification stuff in there it wont echo anything else except an incorrect modified date. If the start is 01/01/2008 it echos 01/21/2008 - thats it. I have put in markers before and after the code and those get echoed, but all the other variables go away... Quote Link to comment https://forums.phpfreaks.com/topic/87230-date-strtotime-question/#findComment-446453 Share on other sites More sharing options...
p2grace Posted January 22, 2008 Share Posted January 22, 2008 Scratch what I put earlier, it doesn't account for the adding of dates correctly. You need to use obsidian's method of adding the date Quote Link to comment https://forums.phpfreaks.com/topic/87230-date-strtotime-question/#findComment-446458 Share on other sites More sharing options...
KrisNz Posted January 22, 2008 Share Posted January 22, 2008 You aren't using strtotime correctly. If you want to add 28 days to a TIMESTAMP its $now = time(); $tsTwentyEightDaysLater = strtotime("+28 day",$now); /*note that by default strtotime uses the current time() as the second argument. I'm just putting that in for clarity. */ //In your case, you want to first convert your mm/dd/yyyy date to a TIMESTAMP $tsUserDate = strtotime($tse_start); //gives us a timestamp $tsTwentyEightDaysLater = strtotime("+28 day",$tsUserDate); //gives us a timestamp $mdyTwentyEightDaysLater = date("m/d/Y",$tsTwentyEightDaysLater); //gives us an m/d/Y formatted date Quote Link to comment https://forums.phpfreaks.com/topic/87230-date-strtotime-question/#findComment-446464 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.