Jump to content

Date manipulation in a variable


alexpb

Recommended Posts

Hey guys,

 

I'm new to this so I'll try give as much detail:

 

I have a list box in which values are taken from the mySQL database, the date values are all stored as 200901, 200812, 200811 and so on, the list item eg 200901, is then stored in a variable $val

eg echo $val; will result in 200901

This is for reporting purposes, the user selects a month for which they'd like a report and clicks on submit, now in the same report I need to show a three month history.

 

In order for me to do this I need to use $val for the current reporting month then subtract one month to get 200812 and later subtract two months to get 200811.

 

When setting the date in the php code it is simple but I have no idea how to have the client recognise the variable as date(Ym).

 

Any assistance in this regard is greatly appreciated, thanks guys.

Link to comment
Share on other sites

What happens is I have users who upload csv data to the database, I use a select distinct on the date field to generate the list, I then use a while statement to add up the totals for each system with that date in the array, as there are several systems for which I need to report.

 

I then need to show a comined total for all systems for a given month over three months, the first being the current for which the report was selected and the two months before.

 

If you believe there is an easier way for me to do this, I'm all ears.

Link to comment
Share on other sites

Quick response to Little Guy,

 

Thanks man, your reply helped me find the solution:

 

$splDate = str_split($val, 4);

$mth1calc = mktime(0,0,0,date("$splDate[1]")-1,date("d"),date("$splDate[0]"));

  $mth1 = date("Ym", $mth1calc);

$mth2calc = mktime(0,0,0,date("$splDate[1]")-2,date("d"),date("$splDate[0]"));

  $mth2 = date("Ym", $mth2calc);

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.