Jump to content

Search the Community

Showing results for tags 'mysql php date datetime'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. I have been trying unsuccessfully to compare two dates using an if statement to then run another query and update a mysql database. I'm not sure where I am going wrong. If I use procedural and use date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $date30))); Then I get an update of every field in the column boosterWithinDays. If I try and use DateTime object $boosterDate = new DateTime($row['boosterDate']); $boosterDate->format("Y-m-d"); Then I get no update at all. I've set some boosterDates to more than 30 days and some to less and nothing seems to work. Here is the complete code: <?php //date_default_timezone_set('America/Chicago'); $todaysDate = new DateTime('now'); $formattedDate = $todaysDate->format('Y-m-d'); $date = new DateTime ('now'); $date90 = $date->add(new DateInterval('P90D')); $date90 = $date->format('Y-m-d'); $date = new DateTime ('now'); $date60 = $date->add(new DateInterval('P60D')); $date60 = $date->format('Y-m-d'); $date = new DateTime ('now'); $date30 = $date->add(new DateInterval('P30D')); //$date30 = $date->format('Y-m-d'); //echo $date90; //echo "<br />"; //echo $formattedDate; $sql = "SELECT * FROM service;"; if(!$result = $con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); } while($row = $result->fetch_array()){ //Get all the rows and store them in an array $firstQueryRows[] = $row; } foreach($firstQueryRows as $row){ //do a new query with $row $patientID = $row['patientID']; $serviceID = $row['serviceID']; //$boosterDate = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $row['boosterDate']))); //$date30 = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $date30))); //$date60 = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $date60))); //$date90 = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $date90))); $boosterDate = new DateTime($row['boosterDate']); //$boosterDate->format("Y-m-d"); if($boosterDate < $date30){ //echo "The date is less than 30" . " " . $row['serviceID'] . "<br /><br />"; //echo $date30 . "<br /><br />"; //echo $boosterDate; $sql = "UPDATE service SET boosterWithinDays = 30;"; if(!$result = $con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); } } } //$date = $row['boosterDate']; //$id = $row['patientID']; //echo $date . " " . $id . "<br /><br />"; //echo date_default_timezone_get(); ?>
×
×
  • 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.