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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 ");

 

 

Link to comment
Share on other sites

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));

Link to comment
Share on other sites

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));

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.