chiefrokka Posted September 4, 2008 Share Posted September 4, 2008 I've been trying to figure this out for over an hour now. been very close but no cigar. trying to play with mktime and strtotime but can't get exactly what i want. how do I add 3 days to a variable pulled from a database. the variable is in the form $Date_Picked = 09/04/2008 I want to add 3 days to $Date_Picked and then compare it to Today. // $Expiration = $Date_Picked + 3 days if today isn't passed expiration (3 days from when they picked), then do code Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 4, 2008 Share Posted September 4, 2008 Well, first off, if you are storing your dates in the DB as a DATE or DATETIME type, you can do it with SQL: SELECT (datecol + INTERVAL 3 DAY) AS expiration FROM table_name; Now, to answer your question directly, try something like this: <?php $date = '9/4/2008'; echo date('m/j/Y', strtotime($date . " + 3 day")); ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted September 4, 2008 Share Posted September 4, 2008 That is also a terrible way to store a date value. Quote Link to comment Share on other sites More sharing options...
chiefrokka Posted September 4, 2008 Author Share Posted September 4, 2008 That is also a terrible way to store a date value. well you gotta give a better solution if your saying it's a terrible way Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 4, 2008 Share Posted September 4, 2008 That is also a terrible way to store a date value. well you gotta give a better solution if your saying it's a terrible way obsidian already did. You need to use a DATE or DATETIME column for maximum capabilities. Quote Link to comment Share on other sites More sharing options...
chiefrokka Posted September 4, 2008 Author Share Posted September 4, 2008 That is also a terrible way to store a date value. well you gotta give a better solution if your saying it's a terrible way obsidian already did. You need to use a DATE or DATETIME column for maximum capabilities. oh, i thought you were commenting on his response. sorry I'm still playing with it because in order to compare you need to have both variables as unix timestamp not just echo. i think it will work this way though. thanks Quote Link to comment Share on other sites More sharing options...
revraz Posted September 4, 2008 Share Posted September 4, 2008 You can compare with either Unix or MySQL Datetime stamps, but not with your method. It may work this way, but you will hate life when you do queries. Do it right the first time. Quote Link to comment 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.