Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare datatime field with current datetime in MySQL

Tags:

sql

mysql

I have something like that:

to_days(now()) < to_days(birth)

It work but instead of comparing days I was to compare the time too. Is there a similar function?

like image 486
rtacconi Avatar asked Apr 13 '10 17:04

rtacconi


People also ask

How can I compare current date and date in MySQL database?

MySQL has the ability to compare two different dates written as a string expression. When you need to compare dates between a date column and an arbitrary date, you can use the DATE() function to extract the date part from your column and compare it with a string that represents your desired date.

How can I compare two date fields in MySQL?

To count the difference between dates in MySQL, use the DATEDIFF(enddate, startdate) function. The difference between startdate and enddate is expressed in days.

Can we compare date with DateTime in SQL?

The right way to compare date only values with a DateTime column is by using <= and > condition. This will ensure that you will get rows where date starts from midnight and ends before midnight e.g. dates starting with '00:00:00.000' and ends at "59:59:59.999".

Can you compare timestamps in SQL?

A date, time, or timestamp value can be compared with another value of the same data type, a datetime constant of the same data type, or with a string representation of a value of that data type. Additionally, a TIMESTAMP WITHOUT TIME ZONE value can be compared with a TIMESTAMP WITH TIME ZONE value.


1 Answers

Why don't you just use:

birth > NOW()
like image 146
Quassnoi Avatar answered Sep 30 '22 09:09

Quassnoi