Jump to content

2 issues, both date related


richei
Go to solution Solved by Barand,

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.

Edited by richei
Link to comment
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;;
Link to comment
Share on other sites

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
Share on other sites

  • Solution

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