How can I subtract 3 days from a date?

Dupre

I have a sync script that syncs domain expiration dates with next due date for billing. Right now the script works great if you want the expiration date to equal the next due date.

But I need the next due date to be three days before the expiration, so I need the code to subtract 3 days from the $expirydate in the following code snippet (Full script code is below):

if ($SyncNextDueDate) {
update_query ( "tbldomains", array ("nextduedate" => $expirydate ), array ("domain" => $domainname ) );
}

Full code:

<?php

require dirname ( __FILE__ ) . '/../../../dbconnect.php';
require ROOTDIR . '/includes/functions.php';
require ROOTDIR . '/includes/registrarfunctions.php';

$cronreport = 'Internet.bs Domain Sync Report<br>
---------------------------------------------------<br>
';
/**
* gets expiration date from domain list command
* @param string $data - command TEXT response
* @return array - associative array having as key the domain name and as value the expiration date
*/
function parseResult($data) {
$result = array ();
$data=strtolower($data);
$arr = explode ( "\n", $data );
$totalDomains = 0;
$assocArr = array ();
foreach ( $arr as $str ) {
    list ( $varName, $value ) = explode ( "=", $str );
    $varName = trim ( $varName );
    $value = trim ( $value );
    if ($varName == "domaincount") {
        $totalDomains = intval ( $value );
    }
    $assocArr [$varName] = $value;

}
if ($assocArr ["status"] != "success") { 
    return false;   
}

for($i = 0; $i < $totalDomains; $i ++) {
    list ( $y, $m, $d ) = explode ( "/", $assocArr ["domain_" . $i . "_expiration"] );
    $status = strtolower ( $assocArr ["domain_" . $i . "_status"] );
            if(!is_numeric($y) || !is_numeric($m) || !is_numeric($d)){
                $ddat = array ("expiry" => null, "status" => $status );
            } else {
                $ddat = array ("expiry" => mktime ( 0, 0, 0, $m, $d, $y ), "status" => $status );
            }
    $result [strtolower ( $assocArr ["domain_" . $i . "_name"] )] = $ddat;
    if (isset ( $assocArr ["domain_" . $i . "_punycode"] )) {
        $result [strtolower ( $assocArr ["domain_" . $i . "_punycode"] )] = $ddat;
    }
}
return $result;
}

$params = getregistrarconfigoptions ( 'internetbs' );

$postfields = array ();
$postfields ['ApiKey'] = $params ['Username'];
$postfields ['Password'] = $params ['Password'];
$postfields ['ResponseFormat'] = 'TEXT';
$postfields ['CompactList'] = 'no';
$testMode = trim(strtolower($params ['TestMode']))==="on";
$SyncNextDueDate = trim(strtolower($params ["SyncNextDueDate"]))==="on";

if ($testMode) {
$url = 'https://testapi.internet.bs/domain/list';
} else {
$url = 'https://api.internet.bs/domain/list';
}

$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );

curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, 0 );

curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_USERAGENT, "WHMCS Internet.bs Corp. Expiry Sync Robot" );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $postfields );

$data = curl_exec ( $ch );
$curl_err = false;


  if (curl_error ( $ch )) {
    $curl_err = 'CURL Error: ' . curl_errno ( $ch ) . ' - ' . curl_error ( $ch );
    exit ( 'CURL Error: ' . curl_errno ( $ch ) . ' - ' . curl_error ( $ch ) );
    }
    curl_close ( $ch );
    if ($curl_err) {
        $cronreport .= "Error connecting to API: $curl_err";
    } else {

    $result = parseResult ( $data );
    if (! $result) {
        $cronreport .= "Error connecting to API:<br>" . nl2br ( $data ) . "<br>";
    } else {
        $queryresult = select_query ( "tbldomains", "domain", "registrar='internetbs' AND (status='Pending Transfer' OR status='Active')" );
        while ( $data = mysql_fetch_array ( $queryresult ) ) {
            $domainname = trim ( strtolower ( $data ['domain'] ) );
            if (isset ( $result [$domainname] )) {
                                if(!is_null($result [$domainname] ["expiry"])){
                                    $expirydate = date ( "Y-m-d", $result [$domainname] ["expiry"] );
                                } else {
                                    $expirydate = false;
                                }
                $status = $result [$domainname] ["status"];
                if ($status == 'ok') {
                    update_query ( "tbldomains", array ("status" => "Active" ), array ("domain" => $domainname ) );
                }
                if ($expirydate) {
                    update_query ( "tbldomains", array ("expirydate" => $expirydate ), array ("domain" => $domainname ) );
                    if ($SyncNextDueDate) {
                        update_query ( "tbldomains", array ("nextduedate" => $expirydate ), array ("domain" => $domainname ) );
                    }
                    $cronreport .= '' . 'Updated ' . $domainname . ' expiry to ' . frommysqldate ( $expirydate ) . '<br>';
                }
            } else {
                $cronreport .= '' . 'ERROR: ' . $domainname . ' -  Domain does not appear in the account at Internet.bs.<br>';
            }
        }
    }
}
logactivity ( 'Internet.bs Domain Sync Run' );
sendadminnotification ( 'system', 'WHMCS Internet.bs Domain Syncronisation Report', $cronreport );

?>
John Conde
$date = new DateTime($expirydate);
$date->sub(new DateInterval('P3D');
$expirydate = $date->format('Y-m-d');

or as a one-liner:

$expirydate = (new DateTime($expirydate))->sub(new DateInterval('P3D'))->format('Y-m-d');

Here's a slightly different method:

$date = new DateTime($expirydate);
$date->modify('-3 days');
$expirydate = $date->format('Y-m-d');

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I subtract 3 days from a date?

From Dev

How to subtract days from a date?

From Dev

bigquery subtract 3 business days from date

From Dev

Subtract days from date

From Java

Subtract days from a date in JavaScript

From Dev

How to Subtract number of days from current date in HQL query

From Dev

Moment JS - how to subtract 7 days from current date?

From Dev

How to subtract 30 days from the current date using SQL Server

From Dev

How to Subtract number of days from current date in HQL query

From Dev

How to subtract 2 months and 18 days from a date

From Dev

How subtract days from date in bash shell on Solaris 11?

From Dev

how can i retrieve date from mysql database and subtract it with current date?

From Java

Subtract days, months, years from a date in JavaScript

From Java

Laravel Carbon subtract days from current date

From Dev

Subtract Business Days from a Specific date

From Dev

Subtract days from a date in a text field

From Dev

Subtract 7 days from today's date

From Dev

Subtract 180 days from current date in Angular

From Dev

how can I get the date picker to start select from at least 8 previous days back from this days date?

From Dev

How to subtract or add days or months to a date on Solaris?

From Dev

How can I subtract timestamp results from `date` in one line of shell?

From Dev

How can I subtract timestamp results from `date` in one line of shell?

From Dev

excel, subtract days from original date to get business days only

From Java

In pandas subtract date from series of date to get series of number of days

From Dev

How do you subtract (X) of Days from (CurrentDateTime) then check with another Date

From Dev

how to subtract the Sundays from no of days in a month

From Dev

How can I echo a date so many days from now using PHP?

From Dev

How can I get 10 days future date from today in Laravel (PHP)

From Dev

How can I create a Vector of weekdays from "Today" to a date 75 days ago in R?

Related Related

  1. 1

    How can I subtract 3 days from a date?

  2. 2

    How to subtract days from a date?

  3. 3

    bigquery subtract 3 business days from date

  4. 4

    Subtract days from date

  5. 5

    Subtract days from a date in JavaScript

  6. 6

    How to Subtract number of days from current date in HQL query

  7. 7

    Moment JS - how to subtract 7 days from current date?

  8. 8

    How to subtract 30 days from the current date using SQL Server

  9. 9

    How to Subtract number of days from current date in HQL query

  10. 10

    How to subtract 2 months and 18 days from a date

  11. 11

    How subtract days from date in bash shell on Solaris 11?

  12. 12

    how can i retrieve date from mysql database and subtract it with current date?

  13. 13

    Subtract days, months, years from a date in JavaScript

  14. 14

    Laravel Carbon subtract days from current date

  15. 15

    Subtract Business Days from a Specific date

  16. 16

    Subtract days from a date in a text field

  17. 17

    Subtract 7 days from today's date

  18. 18

    Subtract 180 days from current date in Angular

  19. 19

    how can I get the date picker to start select from at least 8 previous days back from this days date?

  20. 20

    How to subtract or add days or months to a date on Solaris?

  21. 21

    How can I subtract timestamp results from `date` in one line of shell?

  22. 22

    How can I subtract timestamp results from `date` in one line of shell?

  23. 23

    excel, subtract days from original date to get business days only

  24. 24

    In pandas subtract date from series of date to get series of number of days

  25. 25

    How do you subtract (X) of Days from (CurrentDateTime) then check with another Date

  26. 26

    how to subtract the Sundays from no of days in a month

  27. 27

    How can I echo a date so many days from now using PHP?

  28. 28

    How can I get 10 days future date from today in Laravel (PHP)

  29. 29

    How can I create a Vector of weekdays from "Today" to a date 75 days ago in R?

HotTag

Archive