PHP Date Manipulate Help needed???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
welson
Forum Newbie
Posts: 4
Joined: Sat Oct 11, 2003 9:25 am

PHP Date Manipulate Help needed???

Post 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
User avatar
steedvlx
Forum Contributor
Posts: 122
Joined: Wed Jun 11, 2003 10:54 pm
Location: Osaka, Japan

Post 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
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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"))); 
?>
welson
Forum Newbie
Posts: 4
Joined: Sat Oct 11, 2003 9:25 am

Post by welson »

Thks,

It work

Thank for your help.

Welson
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply