richei Posted May 9, 2014 Share Posted May 9, 2014 ok, i have 2 questions. 1st question - I have a script that i use to execute a java class from apple to pull our sales reports each month, set off from a cronjob. <?php $cc = array('AE','AU','CA','CH','DK','EU','GB','HK','ID','IL','IN','JP','MX','NO','NZ','RU','SA','SE','SG','TR','TW','US','WW','ZA'); $cperiod = date("m",strtotime("+2 month")); // fiscal period $year = 2014; $command = array(); $fname = array(); foreach($cc as $code) { $fname[] = "xxxxxxxxx_".$cperiod."14_".$code; $command[] = 'cd /home/xxxxxx/public_html/admin/files/ && java Autoingestion music.properties xxxxxxxxxxxx '.$code.' DRR '.$year.' '.$cperiod; } for($i=0; $i < count($command); $i++) { if(!file_exists("/home/xxxxx/public_html/admin/files/".$fname[$i])) { exec($command[$i], $out, $err); } else { echo $fname." already exists\r\n"; } } if(isset($out)) { foreach ($out as $line) { echo "$line \r\n"; } } else { foreach ($err as $line) { echo "$code: $line\r\n"; } } ?> My issue won't crop up until January 2015 rolls around. I'm looking for a way to not have to go in every year and change years. If not, then i'll just have to set up 4 years ahead. 2nd question - We just recently started getting sales reports from youtube and the report doesn't include a start or stop date. Without using any manual input (which i'm trying to avoid at all costs), the only way i have of getting the time frame is from the file title (ex. 2014 Jan - Claims Report.csv). What i'm looking for is a way to set the start and stop date into an array using the file title without having to use a crap load of if statements or a seriously long switch. The only other way i know to do this would be to use manual date input and i really want to avoid that, because it means a lot more programming for me. Link to comment https://forums.phpfreaks.com/topic/288360-2-issues-both-date-related/ Share on other sites More sharing options...
Ch0cu3r Posted May 9, 2014 Share Posted May 9, 2014 Use PHP date function to get the current year $year = date('Y'); // returns current year in YYYY format, eg 2014 Does the 14 here represent the year also? $fname[] = "xxxxxxxxx_".$cperiod."14_".$code; If it does you can again replace it with the date function, but instead of Y you'd use y to get the shorthand representation of the year $year_long = date('Y'); $year_short = date('y'); $command = array(); $fname = array(); foreach($cc as $code) { $fname[] = "xxxxxxxxx_{$cperiod}{$year_short}_{$code}"; $command[] = 'cd /home/xxxxxx/public_html/admin/files/ && java Autoingestion music.properties xxxxxxxxxxxx '.$code.' DRR '.$year_long.' '.$cperiod;; Link to comment https://forums.phpfreaks.com/topic/288360-2-issues-both-date-related/#findComment-1478865 Share on other sites More sharing options...
richei Posted May 10, 2014 Author Share Posted May 10, 2014 I found a way around the first issue. Instead of trying to mess with the year, i can use the period. When it hits 1, i need to back a year off and if not, then i use the regular year. and yes, 14 is the year. Anyone have any ideas for the 2nd issue? Link to comment https://forums.phpfreaks.com/topic/288360-2-issues-both-date-related/#findComment-1478953 Share on other sites More sharing options...
Barand Posted May 10, 2014 Share Posted May 10, 2014 here's one way $filename = '2014 Jan - Claims Report.csv'; list($Y, $m) = sscanf($filename, '%s %s - %s'); echo "Year = $Y <br>"; // convert 'Jan' to '1' echo "Month = " . date('n', strtotime("01 $m $Y")); // recognises dd MMM YYYY format /*** OUTPUT *** Year = 2014 Month = 1 */ Link to comment https://forums.phpfreaks.com/topic/288360-2-issues-both-date-related/#findComment-1478983 Share on other sites More sharing options...
richei Posted May 10, 2014 Author Share Posted May 10, 2014 And that's why I come here I guess I'm stuck having to do a switch for setting the start and stop dates. I can only mark 1 solved, but both were. Link to comment https://forums.phpfreaks.com/topic/288360-2-issues-both-date-related/#findComment-1479005 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.