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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple date search

Status
Not open for further replies.

krappleby025

Programmer
Sep 6, 2001
347
0
0
NL
i have the folowing script

$today = date("d-m-Y",time());

which is placed into the database this results in a date formated in 18-01-2004 now

i need to pull from the database the result for yesterdays date... ie 17-01-2004

i have tried

$today = date("d-m-Y",time())-1;

and several variants.. can someone plesae help

thanks
 
These are my personal time manipulation functions. I always use dates in the mysql format for consistancy (YYYY-MM-DD HH:II:SS) which avoids US/UK conversion problems and table formts are "datetime".

function timestamp_from_mysql($timestamp)
{
ereg ("([0-9]{2,4})[^0-9]([0-9]{1,2})[^0-9]([0-9]{1,2})", $timestamp, $regs);
ereg ("([0-9]{2,4})[^0-9]([0-9]{1,2})[^0-9]([0-9]{1,2})[^0-9]([0-9]{1,2})[^0-9]([0-9]{1,2})[^0-9]([0-9]{1,2})", $timestamp, $regs);

if (sizeof($regs)>1)
{
if (sizeof($regs)>4)
{
$date=mktime($regs[4],$regs[5],$regs[6],$regs[2],$regs[3],$regs[1]);
}
else
{
$date=mktime(0,0,0,$regs[2],$regs[3],$regs[1]);
}
}
else
{
$date=0;
}
return $date;
}

function manipulate_mysql_date($date, $movement)
{
// movement is in the following format "+1 days", "+1 hours", "+1 week 2 days 4 hours 2 seconds", "-1 days" etc..
return date ("Y-m-d",strtotime($movement, timestamp_from_mysql($date) ));
}

The only problem with this is that there is a lower limit of 1/1/1970 because of PHPs time function.
 
blimey if its mysql, let the db do the talking..

select blah from whatever where stuff and YOURDATE=date_sub(curdate(), interval 1 day) order by etc etc


substitute the 1 for any number of days going backwards, this will change months and years accordingly.

so interval 366 will give you 2003-01-18 (if today is 2004-01-19).

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top