Re: [newbie]subtracting date

From: Date: Thu, 25 Jan 2001 18:15:18 +0000
Subject: Re: [newbie]subtracting date
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-36676@lists.php.net to get a copy of this message
For PHP's data and time functions, see this page: http://www.php.net/manual/en/html/ref.datetime.html You didn't mention a database - are you going to be selecting records in a database based on a date? I haven't seen this anywhere in the documentation, but my favorite way of doing date math, and the way I've seen other people do it also, is to convert your dates to unix timestamps - that is, convert each date to the number of seconds since 1970, then subtract or add, then convert the result back into a date. $today_seconds = time(); // get current unix timestamp $num_days = 5; $num_days_seconds = (60*60*24*$num_days); $date_before_seconds = $today_seconds - $num_days_seconds; // now convert new date seconds back into a date $date_before = date("m-d-Y", $date_before_seconds); Or use this that I found in the "date" documentation: $five_days_ago_seconds = mktime (0,0,0,date("m"),date("d")-5,date("Y")); $date_5_days_ago = date("m-d-Y", $five_days_ago_seconds); HTH. -- Hardy Merrill Mission Critical Linux, Inc. http://www.missioncriticallinux.com Matthew Ley [matt@jatosoft.com] wrote: > I am working on a project where I need a function that will take the current > date and subtract however many days off of it a client specifies. Would > anybody know a way I can set this up? I pretty new at this so my vocabulary > is very basic. > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#36676) next »