cerebrus189 Posted January 6, 2010 Share Posted January 6, 2010 Hi all, I'm having an issue pulling up a print report(csv file) when the new year started. I didn't write the code but I need help in fixing it. I know its a simple fix of 2-3 lines at the most. This is what the code currently looks like. //get last month for the filenames $lastMonth = sprintf("%02d", date("m") - 1); $thisYear = date("Y"); $fileLastMonth = $thisYear . $lastMonth; $filename[0] = "HP/HPUsage" . $fileLastMonth . ".csv"; $filename[1] = "Lexmark/Room10/mfpUsage_192.168.1.46_" . $fileLastMonth . ".csv"; $friendlyName[1] = "Lexmark Rm 10"; $filename[2] = "Lexmark/Room19/mfpUsage_192.168.2.12_" . $fileLastMonth . ".csv"; $friendlyName[2] = "Lexmark Rm 19"; $filename[3] = "Lexmark/Room29/mfpUsage_192.168.1.32_" . $fileLastMonth . ".csv"; $friendlyName[3] = "Lexmark Rm 29"; $filename[4] = "Lexmark/Room31/mfpUsage_192.168.1.47_" . $fileLastMonth . ".csv"; $friendlyName[4] = "Lexmark Rm 44"; $filename[5] = "Sharp/Sharp_MX-M550N" . $fileLastMonth . ".csv"; $friendlyName[5] = "Sharp Mail Room"; echo "done<br />"; //enumerate the files to read $y = 5; $friendly = 1; //pull last month and year $tablename = date("FY",mktime(0, 0, 0, date("m")-1, date("d"), date("Y"))); I understand its not able to pull "thisYear" because its 2010 and its not looking for last year. I also understand that it doesn't understand the last month is 12/2009 since its now January 2010. Any assistance in fixing this issue permanently would be much appreciated. If I need to post the entire php file, I will but I'm pretty sure the issue lies in these 2-3 lines of code. Link to comment https://forums.phpfreaks.com/topic/187462-date-function-problem-when-switching-to-2010/ Share on other sites More sharing options...
Psycho Posted January 6, 2010 Share Posted January 6, 2010 Replace these lines //get last month for the filenames $lastMonth = sprintf("%02d", date("m") - 1); $thisYear = date("Y"); $fileLastMonth = $thisYear . $lastMonth; With these lines //get last month for the filenames $fileLastMonth = date("Ym", strtotime("last month")); Link to comment https://forums.phpfreaks.com/topic/187462-date-function-problem-when-switching-to-2010/#findComment-989867 Share on other sites More sharing options...
cerebrus189 Posted January 6, 2010 Author Share Posted January 6, 2010 What would I change the "last month" text to? Also I found another line of code that's directly related to the function mentioned previously. //pull last month and year $tablename = date("FY",mktime(0, 0, 0, date("m")-1, date("d"), date("Y"))); Link to comment https://forums.phpfreaks.com/topic/187462-date-function-problem-when-switching-to-2010/#findComment-989904 Share on other sites More sharing options...
Psycho Posted January 6, 2010 Share Posted January 6, 2010 What would I change the "last month" text to? Why would you change it? The strtotime() function will "Parse about any English textual datetime description into a Unix timestamp". So, when it uses "last month" it will literally return a timestamp for last month. And, that is what you want, right? Also I found another line of code that's directly related to the function mentioned previously. //pull last month and year $tablename = date("FY", strtotime("last month")); That must be some really FooBar code if it is creating a different datbase tabe for each month of records. This should work fo rthat line: $tablename = date("FY",mktime(0, 0, 0, date("m")-1, date("d"), date("Y"))); Link to comment https://forums.phpfreaks.com/topic/187462-date-function-problem-when-switching-to-2010/#findComment-989987 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.