473,472 Members | 1,728 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Computing an expiration date

I need to compute an expiration date based on the number of hours,
days, or months purchased.
The expiration date needs to be expressed in minutes something like
'1260481600'.

How can I get the current date and time expressed in minutes?

Once I have this number I can add the number of minutes purchased to
the current date/time to get the expiration date.

Thanks,
Dave

Jul 10 '07 #1
3 3421
On Jul 10, 7:20 am, dave <skny...@sccoast.netwrote:
I need to compute an expiration date based on the number of hours,
days, or months purchased.
The expiration date needs to be expressed in minutes something like
'1260481600'.

How can I get the current date and time expressed in minutes?
round(time()/100/60)
>
Once I have this number I can add the number of minutes purchased to
the current date/time to get the expiration date.

Thanks,
Dave

Jul 10 '07 #2
On 10 Jul, 13:20, dave <skny...@sccoast.netwrote:
I need to compute an expiration date based on the number of hours,
days, or months purchased.
The expiration date needs to be expressed in minutes something like
'1260481600'.

How can I get the current date and time expressed in minutes?

Once I have this number I can add the number of minutes purchased to
the current date/time to get the expiration date.

Thanks,
Dave
divide the unixtime by 60

Jul 10 '07 #3
Here are a series of REALLY USEFUL functions taken from the Zend Code
Galleries that you might fine useful. the link is:
http://www.zend.com/code/codex.php?id=176&single=1
New and Improved! New function mysql_cvdate allows you to take a form-
entered date value and express it in mysql's SQL date format. Also
includes some real-life functions you can call to perform common date/
time conversions between MySQL datetime format, MySQL timestamp format
and UNIX timestamp (i.e. seconds after epoch) with "human" output.
Time left function perfect for auction scripts, or where you need
output of the difference between two supplied times.


<?
function mysql_cvdate($s)
{
//take a user-entered date value and express it in MySQL's
date format
// ***Use this to parse date input from a form into a MySQL
database.
return timestamp_to_mysql_date(cvdate($s));
}
//we use UNIX's time specification as the base specification

function mysql_datetime_to_human($dt)
{
$yr=strval(substr($dt,0,4));
$mo=strval(substr($dt,5,2));
$da=strval(substr($dt,8,2));
$hr=strval(substr($dt,11,2));
$mi=strval(substr($dt,14,2));
// $se=strval(substr($dt,17,2));

return date("m/d/Y H:i", mktime ($hr,$mi,0,$mo,$da,
$yr))." MST";
}

function mysql_date_to_human($dt)
{
//intercept mysql's default ZERO date value.
if ($dt=="0000-00-00") return "";

$yr=strval(substr($dt,0,4));
$mo=strval(substr($dt,5,2));
$da=strval(substr($dt,8,2));

return date("m/d/Y", mktime (0,0,0,$mo,$da,$yr));
}
function mysql_timestamp_to_human($dt)
{

$yr=strval(substr($dt,0,4));
$mo=strval(substr($dt,4,2));
$da=strval(substr($dt,6,2));
$hr=strval(substr($dt,8,2));
$mi=strval(substr($dt,10,2));
//$se=strval(substr($dt,12,2));

return date("m/d/Y H:i", mktime ($hr,$mi,0,$mo,$da,
$yr))." MST";
}

function mysql_timestamp_to_timestamp($dt)
{
$yr=strval(substr($dt,0,4));
$mo=strval(substr($dt,4,2));
$da=strval(substr($dt,6,2));
$hr=strval(substr($dt,8,2));
$mi=strval(substr($dt,10,2));
$se=strval(substr($dt,10,2));

return mktime($hr,$mi,$se,$mo,$da,$yr);
}

function mysql_datetime_to_timestamp($dt)
{
$yr=strval(substr($dt,0,4));
$mo=strval(substr($dt,5,2));
$da=strval(substr($dt,8,2));
$hr=strval(substr($dt,11,2));
$mi=strval(substr($dt,14,2));
$se=strval(substr($dt,17,2));

return mktime($hr,$mi,$se,$mo,$da,$yr);
}

function timestamp_to_mysql_timestamp($ts)
{
$d=getdate($ts);

$yr=$d["year"];
$mo=$d["mon"];
$da=$d["mday"];
$hr=$d["hours"];
$mi=$d["minutes"];
$se=$d["seconds"];

return sprintf("%04d%02d%02d%02d%02d%02d",$yr,$mo,$da,
$hr,$mi,$se);
}

function timestamp_to_mysql_date($ts)
{

$d=getdate($ts);

$yr=$d["year"];
$mo=$d["mon"];
$da=$d["mday"];

return sprintf("%04d-%02d-%02d",$yr,$mo,$da);
}
function timeleft($begin,$end)
{
//for two timestamp format dates, returns the plain english
difference between them.
//note these dates are UNIX timestamps
$dif=$end-$begin;

$years=intval($dif/(60*60*24*365));
$dif=$dif-($years*(60*60*24*365));

$months=intval($dif/(60*60*24*30));
$dif=$dif-($months*(60*60*24*30));

$weeks=intval($dif/(60*60*24*7));
$dif=$dif-($weeks*(60*60*24*7));

$days=intval($dif/(60*60*24));
$dif=$dif-($days*(60*60*24));

$hours=intval($dif/(60*60));
$dif=$dif-($hours*(60*60));

$minutes=intval($dif/(60));
$seconds=$dif-($minutes*60);

$s="";

//if ($years<>0) $s.= $years." years ";
//if ($months<>0) $s.= $months." months ";
if ($weeks<>0) $s.= $weeks." weeks ";
if ($days<>0) $s.= $days." days ";
if ($hours<>0) $s.= $hours." hours ";
if ($minutes<>0) $s.= $minutes." minutes ";
//if ($seconds<>0) $s.= $seconds." seconds ";

return $s;

}

function cvdate($s)
{
//this function takes a "human" date and converts it into a
UNIX timestamp, zero if error.
//this function supports dash,slash or space delimiting,
numeric/english months, and two-digit years.

//what is the delimiting character? (support space, slash,
dash)
$delimiter="";
if (strpos($s,"-")>0) $delimiter="-";
if (strpos($s,"/")>0) $delimiter="/";
if (strpos($s," ")>0) $delimiter=" ";

if ($delimiter=="") return 0;

//chop it up
$p1=strpos($s,$delimiter);
$p2=strpos($s,$delimiter,$p1+1);

$x=substr($s,0,$p1);
$y=substr($s,$p1+1,$p2-$p1);
$z=substr($s,$p2+1);

//debug
// echo("$x/$y/$z");

//the last value is always the year, so check it for 2- to 4-
digit convertion
if (intval($z)<100)
{
if (intval($z)>69) $z=strval(1900+intval($z)); else
$z=strval(2000+intval($z));
}

//intelligently select which converter to use
//(default is M/D/Y, but if the month is "spelled out" then
the format is D/M/Y)
if (intval($y)==0)
{
return cvdate_english($x,$y,$z);
}
else
{
return cvdate_numeric($x,$y,$z);
}

}

//just a helper function
function cvdate_english($d,$m,$y)
{
$d2=0; $m2=0; $y2=0;

$d2=intval($d);

$m=strtolower($m);
switch(substr($m,0,3))
{
case "jan": $m2=1; break;
case "feb": $m2=2; break;
case "mar": $m2=3; break;
case "apr": $m2=4; break;
case "may": $m2=5; break;
case "jun": $m2=6; break;
case "jul": $m2=7; break;
case "aug": $m2=8; break;
case "sep": $m2=9; break;
case "oct": $m2=10; break;
case "nov": $m2=11; break;
case "dec": $m2=12; break;
}

$y2=intval($y);

//check for errors!
if (($d2==0)||($m2==0)||($y2==0)) return 0;

//debug
//echo("$m2/$d2/$y2<br>n");

return mktime(0,0,0,$m2,$d2,$y2);
}

//just a helper function
function cvdate_numeric($m,$d,$y)
{
$d2=0; $m2=0; $y2=0;

$d2=intval($d);
$m2=intval($m);
$y2=intval($y);

//check for errors!
if (($d2==0)||($m2==0)||($y2==0)) return 0;

//debug
//echo("$m2/$d2/$y2<br>n");

return mktime(0,0,0,$m2,$d2,$y2);
}
?>
Hope tis helps

Jul 10 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Christophe Lance | last post by:
Hello, I use PHP session cookie to store an id number. I know how to set a cookie expiration date using the setcookie function, but how to set an expiration date when the cookie is created by...
0
by: Rock | last post by:
Hi,all: I have find a example to set expiration date of word permission object, but it was using VBA code. Dim objUserPerm As Office.UserPermission Set objUserPerm =...
2
by: Frederic Gignac | last post by:
Hiya all, My buddy and I got a bug with the expiration date of a cookie. When we want to look out the expiration date, the only thing we've got, it's 01/01/0001. As we know, when we want to...
4
by: Rickey Tom | last post by:
This has to be a very common question, but my search did not come up with an answer. I needed to set an expiration time for a cookie. In .NET, is seems that the server-side code is used to set...
15
by: Oleg Leikin | last post by:
Hi, (newbie question) I've created some simple .NET ASP application that should store cookies at the client machine. According to the documentation cookie expiration time is set via...
2
by: Bill Borg | last post by:
Hello all, I am working on forms authentication and trying to understand: what's the relationship between the cookie expiration and the ticket expiration? I create a cookie and I add an...
2
by: Jeff Bowman | last post by:
Here's the code: Private Sub SetCookie(ByVal tcEmail As String) Dim loCookie As New HttpCookie("Email") loCookie.Value = Utils.StringToBase64(tcEmail) loCookie.Expires = Now.AddYears(10)...
9
by: Mike Reed | last post by:
I must be having a "senile" day! I cannot recall, nor get to work, code to read a cookie's expiration date/time in an ASP page/VBScript. What am I missing? *** Sent via Developersdex...
1
by: archana | last post by:
Hi all, can anyone tell me difference between absolute expiration and sliding expiration. thanks in advance.
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.