473,718 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
+ 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 3441
On Jul 10, 7:20 am, dave <skny...@sccoas t.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...@sccoas t.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_my sql_date(cvdate ($s));
}
//we use UNIX's time specification as the base specification

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

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

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

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

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

$yr=strval(subs tr($dt,0,4));
$mo=strval(subs tr($dt,4,2));
$da=strval(subs tr($dt,6,2));
$hr=strval(subs tr($dt,8,2));
$mi=strval(subs tr($dt,10,2));
//$se=strval(subs tr($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(subs tr($dt,0,4));
$mo=strval(subs tr($dt,4,2));
$da=strval(subs tr($dt,6,2));
$hr=strval(subs tr($dt,8,2));
$mi=strval(subs tr($dt,10,2));
$se=strval(subs tr($dt,10,2));

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

function mysql_datetime_ to_timestamp($d t)
{
$yr=strval(subs tr($dt,0,4));
$mo=strval(subs tr($dt,5,2));
$da=strval(subs tr($dt,8,2));
$hr=strval(subs tr($dt,11,2));
$mi=strval(subs tr($dt,14,2));
$se=strval(subs tr($dt,17,2));

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

function timestamp_to_my sql_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%0 2d%02d%02d%02d% 02d",$yr,$mo,$d a,
$hr,$mi,$se);
}

function timestamp_to_my sql_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($d if/(60*60*24));
$dif=$dif-($days*(60*60*2 4));

$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,$p 1+1,$p2-$p1);
$z=substr($s,$p 2+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,$m 2,$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,$m 2,$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
4515
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 the session_start function ? I know the cookie expires after the session ends, but when I look at my HTTP headers, the cookie's expiration date created by the session is set to 19
0
1554
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 = ActiveWorkbook.Permission.Add( _ "user@domain.com", _ msoPermissionRead + msoPermissionEdit, #12/31/2005#) ------>set
2
5091
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 create a persitant cookie, we have to put a expiration date, otherwise, it will be a session cookie. So here our code :
4
2227
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 the expiration date of the cookie. More specifically, I've seen several examples (from the Microsoft site) where the cookie information, including the expiration date is set on the server. I wonder how this can work. If the client and server do not...
15
3649
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 HttpCookie.Expires property, but property value is the time of day on the client. How can I possibly know client local time ?
2
1876
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 encrypted ticket to it. Both of these have an expiration date, but I'm not seeing how to use them. Does it make sense that these dates would ever differ? Thanks,
2
1934
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) Response.Cookies.Add(loCookie) End Sub The cookie appears to accept the specified expiration date (i.e. #7/13/2015
9
5519
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 http://www.developersdex.com ***
1
1892
by: archana | last post by:
Hi all, can anyone tell me difference between absolute expiration and sliding expiration. thanks in advance.
0
8827
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8723
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9207
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9120
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9053
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6652
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5971
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3182
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 we have to send another system
3
2122
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.