Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9050501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:39:51+00:00 2026-06-16T12:39:51+00:00

I am trying to check the time right now is newer then a DATETIME

  • 0

I am trying to check the time right now is newer then a DATETIME from a SQL row. This is my current code:

<?php
require('common.php');

$query = "SELECT 
                 event_name, UNIX_TIMESTAMP(event_date) AS event_time, initiator, min_level, max_level
              FROM 
                 DD_events
          WHERE
           event_date <= NOW()
          ";
try{
    $stmt = $db->prepare($query);
    $result = $stmt->execute();
}
catch(PDOException $ex){
    die("Failed to run query: " . $ex->getMessage());
}
$chk = $stmt->fetchall();

//Loop through each row
foreach ($chk as $chks) {
print_r($chks['event_time']); echo "<br>";
  // If it is, create query to make the next event
    $query = "INSERT INTO
              DD_events (event_name, event_date, initiator, min_level, max_level)
              VALUES 
              (:name, :event_date, 0, :min_lvl, :max_lvl)
          ";
  $query_params = array(
                   ':name' => $chks['event_name'],
                   ':event_date' => $chks['event_time'],
                   ':min_lvl' => $chks['min_level'],
                   ':max_lvl' => $chks['max_level']
                   );
    try
    {
        // These two statements run the query against your database table.
        $stmt = $db->prepare($query);
        $stmt->execute($query_params);
    }
    catch(PDOException $ex)
    {
        // Note: On a production website, you should not output $ex->getMessage().
        // It may provide an attacker with helpful information about your code. 
        die("Failed to run query: " . $ex->getMessage());
    }
}

The results always turn up empty even though I know that there are supposed to be turning up.

My goal is to check to see if an event has passed. If it has execute the code.

I understand that PHP time differes from SQL time and that is why I attempted the UNIX_TIMESTAMP() function to try and compare it to the PHP time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T12:39:52+00:00Added an answer on June 16, 2026 at 12:39 pm

    An alternative would be to just select the rows that you need (if you are not going to use the other ones in your code):

    $query = "SELECT 
                event_name, event_date, initiator, min_level, max_level
              FROM 
                DD_events
              WHERE event_date <= NOW()
              ";
    

    That would reduce your php code and the resources needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Check this link! I am having the hardest time trying to figure out why
I'm trying to read a binary file 40 bytes at a time, then check
Right now I'm trying to serve CSS and JS files from a server that
I'm trying to check if a file exists. If I use this: NSData *data
I'm trying delayed_job now, and have some questions. From the http://github.com/collectiveidea/delayed_job page, I can
EDIT:: This might be simple for some but right now it has me confused.
Right now im trying to find a way to detect when an elements HTML
While trying to write code which returns 24 hours less than a given time,
I'm trying to develop a JS function that creates a new row each time
I'm trying to broaden my knowledge of SQL and PHP, so I'm trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.