Jump to content

Trying to understand this code


deansaddigh

Recommended Posts

It takes todays year and stores it in $year, it takes todays month date and stores it in $monthdat, it deducts one from the $year value (giving 2009) it then concatenates that year (ie last year) and month day together before outputting it.

 

So in short, yes.

 

Faux Edit: D'oh.

Thanks that makes it much simpler.

 

One last question i now need to do the same

 

$year = date(NOW());
//Get Current Month
echo $year;
$year --;
$oneyearago = $year;

 

but now the date field is a time stamp and displays like this

2010-01-05 16:14:40

how can i modify my code to work like with the time stamp intead?

Please ignore my last question i have figured it out, but it now leads me onto this one.

 

The database holds a time stamp, heres an example of the time stap in one db record.

 

2008-01-07 11:00:47

 

Basically i have written code to archive some records based if they are a year old.

 

heres my code but it brings back a record with this time and date stamp

 

2010-01-05 16:14:40

 

heres my code and sql statement

 

/***************************************/
/*Archive records one year old/
/***************************************/

//Get Current Year
$year = date('Ymd');
//Get Current Month
echo $year;
$year --;
$oneyearago = $year;

 

Sql code

 

$allQuery = dbExec("SELECT * FROM enquiries WHERE date_requested < '".$oneyearago."' $searchSQL $filterSQL ");

 

 

So are you trying to simply get the date from a year before the date you fetch? Simply use the original code you had, but add strtotime($date) as a second parameter wherever you use the date function (where $date is the DateTime from the database). Like so..

 

$year = date('Y', strtotime($date));

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.