Jump to content

2 issues, both date related


richei

Recommended Posts

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

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;;

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

*/

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.