Page 1 of 2
Add 5 weeks to time stamp
Posted: Wed Oct 26, 2005 11:54 am
by Luke
I am making a seminar schedule that can be added to and deleted from via entries in a database. One of the fields is the seminar start date in the form of a timestamp. I would like to be able to take that timestamp and automatically add 5 weeks plus 2 hours to it. Is that possible to do accurately?
Posted: Wed Oct 26, 2005 12:18 pm
by Burrito
you could use php's
strtotime() function to add the specified time.
ex:
Code: Select all
$date = "10/26/2005";
$newdate = date("m/d/Y",strtotime($date." +5 weeks"));
echo $newdate
Posted: Wed Oct 26, 2005 1:04 pm
by hawleyjr
Posted: Wed Oct 26, 2005 1:07 pm
by Luke
What about just adding 2430000 seconds to the timestamp, which calculates to 5 weeks and 2 hours... is there any reason this would be inaccurate?
Posted: Wed Oct 26, 2005 1:10 pm
by Burrito
that should work too
although, not sure your math is right.
I come up with: 3031200 for 5 weeks and 2 hours.
Posted: Wed Oct 26, 2005 1:11 pm
by hawleyjr
Typically I like to keep as much stuff that can be done in MYSQL in MYSQL.
Code: Select all
"INSERT INTO MY TABLE(tmstamp) VALUES(ADD_TIME(NOW(),5 WEEKS))"
Posted: Wed Oct 26, 2005 1:12 pm
by Chris Corbyn
One armed space goat wrote:What about just adding 2430000 seconds to the timestamp, which calculates to 5 weeks and 2 hours... is there any reason this would be inaccurate?
Only if you cross a DST boundary in that timescale, but generally no.
Using strtotime() makes
far more sense in terms of code readability though
EDIT | I missed the mysql stuff. Always let mysql do as much work as you can.... it's faster than php.
Posted: Wed Oct 26, 2005 1:16 pm
by Luke
Burrito wrote:you could use php's
strtotime() function to add the specified time.
ex:
Code: Select all
$date = "10/26/2005";
$newdate = date("m/d/Y",strtotime($date." +5 weeks"));
echo $newdate
This works for the weeks, but hours come out all funky. I need it to be plus 5 weeks and 2 hours.
Posted: Wed Oct 26, 2005 1:19 pm
by Burrito
Code: Select all
$date = "10/26/2005 10:00:00";
$newdate = date("m/d/Y g:i a",strtotime($date." +5 weeks"));
$newdate = date("m/d/Y g:i a",strtotime($newdate." + 2 hours"));
echo $newdate

Posted: Wed Oct 26, 2005 1:20 pm
by Chris Corbyn
Code: Select all
strtotime(date('m/d/Y'), '+5 weeks and 2 hours'));

Posted: Wed Oct 26, 2005 1:21 pm
by Burrito
d11wtq wrote:Code: Select all
strtotime(date(), '+5 weeks and 2 hours'));

ya or that...

Posted: Wed Oct 26, 2005 1:26 pm
by Luke
d11wtq wrote:Code: Select all
strtotime(date('m/d/Y'), '+5 weeks and 2 hours'));

That made this happen..
error wrote:
Warning: date() [function.date]: Windows does not support dates prior to midnight (00:00:00), January 1, 1970 in e:\Inetpub\wwwroot\classes.php on line 16
10/26/05 3:09 and PHP Warning: date() [function.date]: Windows does not support dates prior to midnight (00:00:00), January 1, 1970 in e:\Inetpub\wwwroot\classes.php on line 16
Posted: Wed Oct 26, 2005 1:27 pm
by Burrito
try removing the "and"
so just "5 weeks 2 hours"
Posted: Wed Oct 26, 2005 1:29 pm
by Chris Corbyn
Sorry, date() shouldn't be there
Look at Burrito's first example and you'll figure it out

Posted: Wed Oct 26, 2005 1:32 pm
by Burrito
I think the "and" is what is causing that error though.
I'm pretty sure the correct syntax for adding multiple "types" with strtotime is just a space separator...try what I just posted and see if it works.