Forum Moderators: coopster

Message Too Old, No Replies

How can I get a future date?

         

Raghav

5:09 am on Aug 18, 2009 (gmt 0)

10+ Year Member



I have got a variable $datecreated with the type - (timestamp). Whenever a new user is created the $datecreated variable stores the date on which the user is created. Now if I want to show 6 month later date based on the $datecreated variable, what should I do?

Pls help me in the process.

Thank you,
Raghav

Habtom

5:14 am on Aug 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you storing it somewhere: database, text file, ... ?

Raghav

5:20 am on Aug 18, 2009 (gmt 0)

10+ Year Member



Yes I am. It is stored in a database. And the variable is $datecreated.

dreamcatcher

5:56 am on Aug 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



strtotime [uk3.php.net]

dc

Habtom

6:01 am on Aug 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



strtotime("+6 months", $datecreated);

Raghav

6:03 am on Aug 18, 2009 (gmt 0)

10+ Year Member



Is it echo "strtotime("+6 months", $datecreated);?

Raghav

6:09 am on Aug 18, 2009 (gmt 0)

10+ Year Member




I used as Course End Date: <?php strtotime("+6 months", $datecreated);

A PHP Error was encountered

Severity: Notice

Message: A non well formed numeric value encountered

Filename: template_student/active_history.php

Line Number: 17

Habtom

7:04 am on Aug 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe more like:

echo date('Y-m-d', strtotime("+6 months", $datecreated));

Raghav

7:13 am on Aug 18, 2009 (gmt 0)

10+ Year Member



I used as <?php echo date('l M dS Y', strtotime("+6 months", $created)); ?>

Am sorry Habtom to trouble you, I tried what you gave - I got an error as below. But I got a date as - Wednesday Jul 01st 1970, below the following error.

A PHP Error was encountered

Severity: Notice

Message: A non well formed numeric value encountered

Filename: template_student/active_history.php

Habtom

8:07 am on Aug 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$datecreated or $created as you put it?

I think it is best for you to disable the notices for now.

<?php error_reporting(E_ALL & ~E_NOTICE); ?>
When going live you can disable all errors.

Raghav

11:02 am on Aug 18, 2009 (gmt 0)

10+ Year Member



I used that, but the future date is only showing Jul 01 1970, even if the user was created today i.e - Aug 18 2009. It should have shown - Feb 18 2009.

Please help.

Habtom

11:15 am on Aug 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



echo date('Y-m-d', strtotime("+6 months", mktime($datecreated)));

I am sure there is a simpler version, but that should work.

Raghav

11:35 am on Aug 18, 2009 (gmt 0)

10+ Year Member



Am sorry for keeping on pestering. But now for all the users - it is showing the same date as Nov-09-2010. Even for the users created now and user created 3 months back.

Habtom

12:29 pm on Aug 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That could be because the right data is not fed to that line. How are you getting the value in the variable $datecreated? You need to post small portion of your code surrounding this line echo date('Y-m-d', strtotime("+6 months", mktime($datecreated)));

Raghav

4:05 am on Aug 19, 2009 (gmt 0)

10+ Year Member



I've selected the default field for the variable $datecreated as CURRENT_TIMESTAMP. That gives value of variable whenever a user is created.