Kopieringsrapporter - räkna fram perioder utifrån dagens datum - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of Kopieringsrapporter - räkna fram perioder utifrån dagens datum.php
- <?php
- $Dates = PrintCountStartStop();
- foreach($Dates as $Dt)
- {
- echo "<p>" . date("Y-m-d H:i:s",$Dt) . "</p>";
- }
- function PrintCountStartStop()
- {
- $CurrPeriodEnd = mktime(11,8,59,3,1,2022);
- //$CurrPeriodEnd = time(); // Alltså just nu!
- $CurrYear = (int) date("Y",$CurrPeriodEnd);
- $CurrMonth = (int) date("m",$CurrPeriodEnd);
- $CurrPeriodStartYear = $CurrMonth < 3 ? $CurrYear - 1 : $CurrYear;
- $InvoicePeriodStartYear = $CurrPeriodStartYear - 1;
- $CurrPeriodStartDate = mktime(0,0,0,3,1,$CurrPeriodStartYear);
- $InvoicePeriodEndDate = $CurrPeriodStartDate - 1; // En sekund tidigare än startdatum
- // för löpande period
- $InvoicePeriodStartDate = mktime(0,0,0,3,1,$InvoicePeriodStartYear);
- $RetVal = array();
- $RetVal['invoicestart']= $InvoicePeriodStartDate;
- //fablog('invoicestart',date("Y-m-d H:i:s"));
- $RetVal['invoicestop'] = $InvoicePeriodEndDate;
- $RetVal['currperiodstart'] = $CurrPeriodStartDate;
- $RetVal['currperiodend'] = $CurrPeriodEnd;
- return $RetVal;
- }