Page 1 of 1

date and time problem

Posted: Wed Jul 02, 2003 9:45 pm
by robin1
Hello everybody..
trying to add a number of days to the day1 variable to show the expired date but it's not working..
the example i followed:
http://www.phpbuilder.com/columns/akent ... hp3?page=5
but it's doesn't seem to work.. can someone look at this code and let me know what i'm doing wrong.

Code: Select all

<?
$timestamp = time();
echo "current time stamp -->: ".$timestamp;
echo "<p>";
$date_time_array = getdate($timestamp);
$day1 = $date_time_array["mday"];
$month1 = $date_time_array["month"];
$year1 = $date_time_array["year"];

echo "example 1 --> ".$month1." ".$day1." ".$year1."<p>"; //works
$date1 = mktime(0, 0, 0, $month1, $day1+15, $year1);

echo "<p>";
echo "exp date ". strftime("%A %d %b", $date1);
?>
Thanks

Posted: Thu Jul 03, 2003 3:54 am
by twigletmac
Try this - it just works with the timestamps and cuts out the intermediate getdate() stuff:

Code: Select all

<?php 

$timestamp = time(); 
echo '<p>current time stamp -->: '.$timestamp.'</p>'; 
echo '<p>current day -->: '.date('F d Y', $timestamp);

$expiry_ts = $timestamp + 15*24*60*60;
echo '<p>expiry timestamp: '.$expiry_ts.'</p>';
echo '<p>expiry date: '.date('F d Y', $expiry_ts);
?>
Mac

Posted: Thu Jul 03, 2003 6:59 am
by robin1
how would this work with mysql database.. i have the time() saved as int. in the db..
I tried copy/pasted the results of time() as what you see below but it displayed aug. 2, 2003 insted of 15 day exp. date
i tried $timestamp = "1058529275"; to test and it didn't work.

Posted: Thu Jul 03, 2003 7:12 am
by twigletmac
The output from the code should look something like this:

Code: Select all

current time stamp -->: 1057234186

current day -->: July 03 2003

expiry timestamp: 1058530186

expiry date: July 18 2003
The first timestamp is for todays date and the second for 15 days from today. You would get Aug 2 if you added 15 days to the second timestamp and '1058529275' is a version of the second timestamp.

Mac