Jump to content

Problem with Dates


anser316

Recommended Posts

Hi i have a problem with selecting rows from MySQL onto PHP which have a date in the current month, previous month, previous year and current year (they will be on seperate forms)

e.g. ID  date

      01  2008-03-24

      03 2008-02-01

      04 2007-03-04

 

PHP

    current month

          01

 

previous month

        02        etc

 

i was thinking maybe to stick the date into a variable, and find that using php but i am not sure

Link to comment
Share on other sites

mktime wrapped inside of the date function with use of explode is you're friend for instance.

 

$currentDate=date('Y-m-d'); // you probably want to store the date the user is viewing as a GET variable
$dateArr=explode($currentDate,'-');
$nextDate=date('Y-m-d',mktime('12','0','0','0',$dateArr[2],$dateArr[1]-1,$dateArr[0]));

 

The syntax in that is probably wrong, but you look up those functions and you should be able to figure the exact syntax out based on what I gave you.  I'd do it, but my hash browns are almost done.  Good luck.

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.