thenext88 Posted January 7, 2007 Share Posted January 7, 2007 So I really don't know how to make a "time difference" script, and I sort of need one. I'm also still new with php, so if I did some stupid things like put variables where they shouldn't be, please let me know as well.I need a script that can take a date given in m d Y g:i format, and find out the difference between the current, and that date.I tried to make a test script, which failed, because I keep getting 0 as my answer.Any suggestions and help would be greatly appreciated.[code]<?php$time = date('m d Y g:i');echo "$time";echo "<br><br>";$tomorrow = mktime(date("g"),date("i"),0,date("m"),date("d")+1,date("Y"));echo "Tomorrow is ".date("m d Y g:i", $tomorrow);echo "<br><br>";$start = strtotime ($time);$end = strtotime ($tomorrow);$diff = $end - $start;echo "$diff";?>[/code] Link to comment https://forums.phpfreaks.com/topic/33177-need-help-with-a-time-difference-script/ Share on other sites More sharing options...
Jessica Posted January 7, 2007 Share Posted January 7, 2007 Take the $_GETs out...you're not getting anything from the url. You already have your variables.$start = strtotime ($time);$end = strtotime ($tomorrow);$diff = $end - $start; Link to comment https://forums.phpfreaks.com/topic/33177-need-help-with-a-time-difference-script/#findComment-154830 Share on other sites More sharing options...
thenext88 Posted January 7, 2007 Author Share Posted January 7, 2007 [quote author=jesirose link=topic=121338.msg498777#msg498777 date=1168148006]Take the $_GETs out...you're not getting anything from the url. You already have your variables.$start = strtotime ($time);$end = strtotime ($tomorrow);$diff = $end - $start;[/quote]Ok, modified, and testing.Edit: I still get 0 as an answer. Link to comment https://forums.phpfreaks.com/topic/33177-need-help-with-a-time-difference-script/#findComment-154831 Share on other sites More sharing options...
Jessica Posted January 7, 2007 Share Posted January 7, 2007 What is the entire output?$tomorrow is already a timestamp, so you don't need to run strtotime on it again. PS: tomorrow is time()+(60*60*24). A lot easier than what you have IMO. Link to comment https://forums.phpfreaks.com/topic/33177-need-help-with-a-time-difference-script/#findComment-154833 Share on other sites More sharing options...
thenext88 Posted January 7, 2007 Author Share Posted January 7, 2007 The entire output was:01 07 2007 12:40Tomorrow is 01 08 2007 12:400The reason I have one timestampe and the other not as current time is because I have a MySQL database that contains a date of entry. And this date of entry, is what has to be subracted from the current time, which is why I am trying to get this work.And when I removed strtotime from $tomorrow, I got:01 07 2007 12:40Tomorrow is 01 08 2007 12:401168278000 Link to comment https://forums.phpfreaks.com/topic/33177-need-help-with-a-time-difference-script/#findComment-154836 Share on other sites More sharing options...
Jessica Posted January 7, 2007 Share Posted January 7, 2007 Well that's a bit better.Did you set $end = $tomorrow? Link to comment https://forums.phpfreaks.com/topic/33177-need-help-with-a-time-difference-script/#findComment-154837 Share on other sites More sharing options...
thenext88 Posted January 7, 2007 Author Share Posted January 7, 2007 [quote author=jesirose link=topic=121338.msg498784#msg498784 date=1168148727][quote author=jesirose link=topic=121338.msg498780#msg498780 date=1168148338]$tomorrow is already a timestamp, so you don't need to run strtotime on it again. [/quote]Take out the strtotime call on $tomorrow and try again. $end = $tomorrow.[/quote]I did that, and the answer is now 1168278000 ???And yes, I set $end = $tomorrowcode is now[code]<?php $time = date('m d Y g:i');echo "$time";echo "<br><br>";$tomorrow = mktime(date("g"),date("i"),0,date("m"),date("d")+1,date("Y"));echo "Tomorrow is ".date("m d Y g:i", $tomorrow);echo "<br><br><br>";$start = strtotime ("$time");$end = $tomorrow;$diff = $end - $start;echo "$diff";?>[/code] Link to comment https://forums.phpfreaks.com/topic/33177-need-help-with-a-time-difference-script/#findComment-154838 Share on other sites More sharing options...
Jessica Posted January 7, 2007 Share Posted January 7, 2007 Which I bet is the timestamp for today, meaning $end = 0. See my above post. Link to comment https://forums.phpfreaks.com/topic/33177-need-help-with-a-time-difference-script/#findComment-154840 Share on other sites More sharing options...
thenext88 Posted January 7, 2007 Author Share Posted January 7, 2007 Fixed! Two time stamps work. I just made the current time a time stamp, and then got rid of strotime for $time, and it worked.Thanks for the help Link to comment https://forums.phpfreaks.com/topic/33177-need-help-with-a-time-difference-script/#findComment-154842 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.