Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 503
  • Last Modified:


can someone explain to me this line of code:
datediff(now(),post_date) = 0
3 Solutions
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
Lee SavidgeCommented:
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.
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.


Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

karinos57Author Commented:
yeah, this is mysql code. thx
Lee SavidgeCommented:
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: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_datediff

karinos57Author Commented:

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now