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 Link to comment https://forums.phpfreaks.com/topic/122766-adding-3-days-to-a-variable/ 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")); ?> Link to comment https://forums.phpfreaks.com/topic/122766-adding-3-days-to-a-variable/#findComment-633919 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. Link to comment https://forums.phpfreaks.com/topic/122766-adding-3-days-to-a-variable/#findComment-633927 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 Link to comment https://forums.phpfreaks.com/topic/122766-adding-3-days-to-a-variable/#findComment-633938 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. Link to comment https://forums.phpfreaks.com/topic/122766-adding-3-days-to-a-variable/#findComment-633951 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 Link to comment https://forums.phpfreaks.com/topic/122766-adding-3-days-to-a-variable/#findComment-633954 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. Link to comment https://forums.phpfreaks.com/topic/122766-adding-3-days-to-a-variable/#findComment-633980 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.