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
https://forums.phpfreaks.com/topic/97602-problem-with-dates/
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
https://forums.phpfreaks.com/topic/97602-problem-with-dates/#findComment-499386
Share on other sites

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.