Jump to content

Converting Day of Year to real date in the future


phoenixx

Recommended Posts

I have a database that outputs the following:

$signupdoy = ($row['clients_signupdoy']);  // Signup Numeric Day of Year

$signupdate = ($row['clients_signupdate']);  // Signup 2 Digit Date

$signupmonth = ($row['clients_signupmonth']);  // Signup 2 Digit Month

$signupyear = ($row['clients_signupyear']);  // Signup 4 Digit Year

 

I've searched the mktime and strtotime functions :rtfm:, but seem to be drawing a blank.  I could really use some help on the following:

 

  • Converting the signup date to a date 7 days later (to know when the free trial ends). I know I could just do $signupdoy+7 but I need to show it as an actual date on the client's account page.
  • Converting the signup date to a monthly billing date, keeping in mind that if the user signs up on the 29th, 30, or 31st that there are some days that don't go that high.
  • Ensuring that the 7 day and monthly anniversary dates are compliant when going from one year to the next.

 

I would like to output the code like: dd.mm.yyyy

 

I know it's got to be just a few lines of code, but everything I've tried has come up negative. :shrug:  Any help the forum could give me would be greatly appreciated.

Post the code to create the date.  Sorry, my bad.  Your looking for a way to do it.

 

strtotime() works to get a times tamp. Then just add the number of seconds in 7 days and add it to the time stamp.  Finally, use date() to format the time stamp.

Why not just use the getdate() and use the 0 for the number of seconds since epoch. Then just add seven days worth of seconds to the current date and use that number as a reference.

http://us.php.net/manual/en/function.getdate.php

$time_I_reg = getdate();

echo $time_I_reg[0]; // will display the seconds since epoch for that that date.
$temp_time = $time_I_reg[0] + $sevendaysofseconds; // will add seven days 
$time_ends = getdate($temp_time);

echo $time_ends[month]." ".$time_ends[mday];

 

  * Converting the signup date to a date 7 days later (to know when the free trial ends). I know I could just do $signupdoy+7 but I need to show it as an actual date on the client's account page.

    * Converting the signup date to a monthly billing date, keeping in mind that if the user signs up on the 29th, 30, or 31st that there are some days that don't go that high.

    * Ensuring that the 7 day and monthly anniversary dates are compliant when going from one year to the next.

 

//07.02.2010 = sign up date.
$date = date('d.m.Y',strtotime('+7 days',strtotime("$signupdate-$signupmonth-$signupyear")));
//14.02.2010 = output date.

I'm sorry, he asked a question.  He knew what functions to use.  He couldn't figure it out.  So yes, he has the code, now he knows the answer. 

 

I'm not that smart, I just had help when I started out.  The same kind of help I just gave, and not vague suggestions dancing around an answer.

 

BTW, strtotime() does care which way you insert the date into it.  Giving it a "mm-dd-yyyy" will return the wrong date.  It looks for "dd-mm-yyyy".

Many thanks to both TheBG & jcbones.  Got it figured out before the posts, but jcbjones code is cleaner than mine.  Wound up using the following.

<? echo date('m.d.Y',strtotime('+7 days',strtotime("$signupdate-$signupmonth-$signupyear"))) . " (" . (($acctsignupdoy+6)-date('z')) . " days)";?>

 

Thanks again for all the help!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.