Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date manipulation

Status
Not open for further replies.

Ant0

Technical User
May 3, 2005
17
GB
Hi there

New to PHP and am struggling with a simple program I want to write. I have an HTML page which asks for a date (i.e. what date did you attend the course), I then get that data and populate a constant with it via $_POST['date_entered'].

I now want to take that date and populate a variable with it, plus one year, and then with this new variable subtract it from todays date so I can output the number of days between now and the future date.

I hope this makes sense, I am banging my head on the keyboard now!

My code is below, but if does not give the results I want:

<?php
session_start();
$_SESSION['sab']=$_POST['sab'];
echo $_SESSION['sab'];
$days_so_far = date("d/m/Y")-$_SESSION['sab'];

$year=substr($_SESSION['sab'],6,4)+1;
$month=substr($_SESSION['sab'],3,2);
$day = substr($_SESSION['sab'],0,2);

$year_ahead= $day . "/" . $month . "/" . $year;
$weeks_so_far = round($days_so_far/7,0);

$days_to_go = $year_ahead-date("d/m/Y");

echo "So far you have been back " . $days_so_far . " days<br>";
echo "Which is " . $weeks_so_far . " weeks<br>";
echo "You have " . $days_to_go . " days to go<br>";
echo "Which is " . $weeks_to_go . " weeks to go<BR>";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top