Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2008
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Compare Mysql current timestamp with todays date

    Hi there, I'm looking to compare a timestamp that was automatically created by the mysql database when each record was created with todays date. Firstly i believe i have to get it into the same format tho and was looking for pointers on how to do this.

    Currently if i echo the value of the timestamp in one of the database records it reads: 2008-02-15 15:31:14

    Been looking around but haven't had much luck on this, so wondering if you guys could help.

    Cheers

  • #2
    New Coder
    Join Date
    Feb 2008
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Have kinda got it working, although aving problems comparing if the date posted equas todays date.

    Here's what i have:
    Code:
    $todays_date = date("d M Y");
    $today = strtotime($todays_date);
    $date = date("d M Y", strtotime($row["date_posted"]));
    if($date == $today){
    $dateposted = "Today";
    
    }
    else {
    $dateposted = $date;
    }
    It is in a while statement that shows a number of records on the page at once, altho i don't think this shud interfere with it as it is in the while statement and shud happen for each record.

    Any ideas? Is it not possible to use = when comparing dates?

  • #3
    New Coder
    Join Date
    Feb 2008
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Sorry, guys never mind about bout this, have seen my error. I didn't need line:

    Code:
    $today = strtotime($todays_date);
    Have it working now

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,146
    Thanks
    2
    Thanked 333 Times in 325 Posts
    If you want to know if a date (in a DATETIME) field in your database is equal to the current date, do it directly in your query. No conversion or slow php code is necessary -

    Code:
    SELECT your_columns FROM your_table WHERE DATE(date_posted) = CURDATE()
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •