Jump to content

TODAY + 1 do this, + 2 do this.... ANYONE???


chocolate

Recommended Posts

Hi, I am so freaking new to PHP... I want to create a code in which I state the date. And based on that date I can show a CODEWORD, or image on future dates.

 

So, let's say the date is 06-19-2008,

now...

if its +1 day it will echo this

if its +2 days it will echo this

if its +3 days it will echo this...... and so on.

 

This is what I came up with, but can't seem to make it work...

 

$startdate = '06/19/2007';

if ($newdate == date('m/d/Y', strtotime("+1 days", strtotime($startdate)))) echo "first<br>";

if ($newdate == date('m/d/Y', strtotime("+2 days", strtotime($startdate)))) echo "second<br>";

if ($newdate == date('m/d/Y', strtotime("+3 days", strtotime($startdate)))) echo "third<br>";

 

it doesn't work... it just writes all the dates... -=( I need this to show one code per day from a starting date.

 

Thanks

P.S.

in the past, I did this: but it sux because I have to change the dates all the time I need a new one.

 

$today = date("m-d-Y");

      if ($today == date("05-16-2008")) { $video1 = 343KOSLL31';}

      if ($today == date("05-17-2008")) { $video1 = '5MK78hZL3o0';}

      if ($today == date("05-18-2008")) { $video1 = '5xNZ5CC0gvk';}

      if ($today == date("05-19-2008")) { $video1 = '3q2vZDQU8aA';}

      if ($today == date("05-20-2008")) { $video1 = 'BfWIP02g41g';}

      if ($today == date("05-21-2008")) { $video1 = 'lawXkvPFRgI';}

 

HEEEEEEEEEEEELP... anyone??? ???

Link to comment
Share on other sites

Try this

 

$startdate = '06/19/2007';
if ($newdate == date('m/d/Y', strtotime("+1 days", strtotime($startdate)))) 
{ echo "first }";
elseif ($newdate == date('m/d/Y', strtotime("+2 days", strtotime($startdate)))) 
{ echo "second }";
elseif ($newdate == date('m/d/Y', strtotime("+3 days", strtotime($startdate)))) 
{ echo "third }";

Link to comment
Share on other sites

if I can do it without a starting date... how would I be able to accomplish it?

 

How would it know what code to pull based on the date?

 

For example... it has to start let's say today 06/19/2008

 

and today it will show the code "FIRST"

 

then tomorrow (+1 day) should show "SECOND"

and so on...

 

how can I pull it off without a starting date?

Link to comment
Share on other sites

always the same code for each relative day though?

 

Today will always have the same code.  When tomorrow is today, it will have the same code as today, and the day after tomorrow will have the same code as tomorrow when tomorrow is today (whew...that's confusing).

 

<?php

$today = 'abc';
$tomorrow = 'def';
$day_after_that = 'ghi';

echo 'Today is: ' . date("Y-m-d") . ' and the code is: ' . $today;
echo 'Tomorrow is ' . date("Y-m-d", mktime(null, null, null, date("m"), date("d") + 1, date("Y"))) . ' and the code is ' . $tomorrow;
echo 'The day after tomorrow is ' . date("Y-m-d", mktime(null, null, null, date("m"), date("d") + 2, date("Y"))) . ' and the code is ' . $day_after_that;

Link to comment
Share on other sites

well... I guess I need to explain better what I want to accomplish.

 

This is what I have done in the past:

<?

$today = date("m-d-Y");

if ($today == date("06-19-2008")) echo "THE CODE FOR TODAY IS RED";

if ($today == date("06-20-2008")) echo "THE CODE FOR TODAY IS BLUE";

if ($today == date("06-21-2008")) echo "THE CODE FOR TODAY IS GREEN";

?>

 

As you can see, it gives me a different code depending on the date

- RED for the June 19

- BLUE for June 20

- Green for June 21

 

Now, the problem I have with this is that themore codes I have, the more I have to update the dates manually.

 

So I have always insert 06-22-2008, 06-23-2008 and so on.....

 

So I want to get rid of all that manual work and have a script that already knows that its the NEXT DAY.

 

So it starts today - CODE RED

When it realizes that its one day after it will give me CODE BLUE

and then a day after that will give me GREEN....

 

 

Makes sense?

I need to show only one code per day,... but each code is different.... and it needs to know what code was given the day before.

 

 

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.