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
PHP Date Manipulate Help needed???
Moderator: General Moderators
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
How to increment Dates retrieved with queries:
viewtopic.php?t=11373&highlight=
I believe that will answer your question.
SteedVLX
Heres an easy way to do it:
edit--
found an even easier way:
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
?>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")));
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Using the database to set the date would be even easier. Assuming you are using MySQL:
Mac
Code: Select all
Update Atten SET NextVisit=DATE_ADD(NOW(), INTERVAL 3 DAY) WHERE StudentID='$studenid'