Posted on 2011-10-05
Last Modified: 2012-06-27
can someone explain to me this line of code:
datediff(now(),post_date) = 0
Question by:karinos57
    LVL 15

    Assisted Solution

    Where are you trying to run this?  The following would be checking to see if the dates match each other.  What you posted wouldn't run in SQL unless you've created some custom functions.

    datediff(d,getdate(),post_date) = 0
    LVL 25

    Accepted Solution

    Is this mySQL code?

    If so, datediff subtracts one date from another so this is checking to see if the result is 0 days as I suspect this is part of an if statement or a select where clause.
    LVL 21

    Assisted Solution

    You have posted this in the SQL Server areas, but it actually looks like Access.  Now() is an Access function.  It also looks like you are missing an argument.  The syntax should be DATEDIFF(interval, date1, date2) where interval is the unit of time(days, hours, seconds, milliseconds, etc) and date1 is the start date and date2 is the end date.  The function returns the number of time units between the two dates.  The code you posted, if rewritten correctly, is looking for a value in post_date that is exactly the same as the current date time.



    Author Comment

    yeah, this is mysql code. thx
    LVL 25

    Expert Comment

    by:Lee Savidge
    If the code is part of a where clause, then it will return all records that are zero days apart. DateDiff in mySQL will take 2 parameters. It will subtract, in your case, now() which is the time and date as it is now, from the post_date which is a field in the table and if the result is zero it will return the record.

    See here:


    Author Closing Comment


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (, A SQLite Tidbit: Quick Numbers Table Generation (…
    Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now