alexpb Posted February 23, 2009 Share Posted February 23, 2009 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. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 23, 2009 Share Posted February 23, 2009 I am not sure why a timestamp, or unix timestamp isn't being used here, it would make most sense... but, not sure if this helps, but this is how you would do something with it in php... $mDate = '200911'; $splDate = str_split($mDate, 4); echo $splDate[0]; // This is the year echo $splDate[1]; // This is the month Quote Link to comment Share on other sites More sharing options...
gizmola Posted February 23, 2009 Share Posted February 23, 2009 In an html select element, there is a difference between what is displayed and what is the value for an element in the select list. It's basic HTML markup. Quote Link to comment Share on other sites More sharing options...
alexpb Posted February 23, 2009 Author Share Posted February 23, 2009 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. Quote Link to comment Share on other sites More sharing options...
alexpb Posted February 24, 2009 Author Share Posted February 24, 2009 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); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.