Page 1 of 1

PHP Date Manipulate Help needed???

Posted: Sat Oct 11, 2003 9:25 am
by welson
Hi,

Is anyone can help me on this?

I'm writing a code and want to manipulate the date in php then store it to database.

My question:

I had set the database fields value as follow:

NextVisit date NOT NULL default '0000-00-00',

what I want is to update this fields with the value + 3 days from date is visited.

If today date is 2003-09-23, if student visit page today and then the system will automate update the NextVisit date with the value + 3 days, it means the date to update to the database would be 23+3 = 2003-09-26

see my code here:
$todaydate=".date("Y/m/d")."
$NextVisit= ???????? // here should be the day + 3 days, how the code will be? or any code needed before can get this date?

$query = "Update Atten SET NextVisit='$NextVisit' WHERE StudentID='$studenid'";
mysql_query($query) or die("Bad query: ".mysql_error());

Thanks for whoever will to help

Posted: Sat Oct 11, 2003 10:36 am
by steedvlx
Take a look at this thread. It helped me tremendously.

How to increment Dates retrieved with queries:

viewtopic.php?t=11373&highlight=

I believe that will answer your question.

SteedVLX

Posted: Sat Oct 11, 2003 11:13 am
by DuFF
Heres an easy way to do it:

Code: Select all

<?php
$todaydate = date("Y-m-d");
$days_to_add = 3;
$nextvisit = strftime("%Y-%m-%d", strtotime("$date + $days_to_add days"));
echo $nextvisit; //will output 2003-10-14, today is 2003-10-11
?>
edit--
found an even easier way:

Code: Select all

<?php
$NextVisit = date("Y-m-d",mktime(0,0,0,date("m"),date("d")+3,date("Y"))); 
?>

Posted: Sun Oct 12, 2003 1:24 am
by welson
Thks,

It work

Thank for your help.

Welson

Posted: Mon Oct 13, 2003 3:27 am
by twigletmac
Using the database to set the date would be even easier. Assuming you are using MySQL:

Code: Select all

Update Atten SET NextVisit=DATE_ADD(NOW(), INTERVAL 3 DAY) WHERE StudentID='$studenid'
Mac