Jump to content

adding 3 days to a variable


chiefrokka

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.