Add 5 weeks to time stamp
Moderator: General Moderators
Add 5 weeks to time stamp
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?
you could use php's strtotime() function to add the specified time.
ex:
ex:
Code: Select all
$date = "10/26/2005";
$newdate = date("m/d/Y",strtotime($date." +5 weeks"));
echo $newdateTypically 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))"- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Only if you cross a DST boundary in that timescale, but generally no.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?
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.
This works for the weeks, but hours come out all funky. I need it to be plus 5 weeks and 2 hours.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
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- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Code: Select all
strtotime(date('m/d/Y'), '+5 weeks and 2 hours'));ya or that...d11wtq wrote:Code: Select all
strtotime(date(), '+5 weeks and 2 hours'));
That made this happen..d11wtq wrote:Code: Select all
strtotime(date('m/d/Y'), '+5 weeks and 2 hours'));
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
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia