954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to match Todays date in sql

Hi All
I want to check whether there is a record present in my database with value:
StartDate="Todays's Date"
where start date is the column name with datatype DATE.

Masood Ali
Newbie Poster
19 posts since Mar 2007
Reputation Points: 10
Solved Threads: 1
 

Use PreparedStatement and new Date (using java.sql.Date not java.util.Date).

If you question is how to formulate a query in general, then please find an SQL forum.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

If you have a query to fire , then use the SYSDATE as the standard one.
For example, on Oracle if I query as follows,

"select SYSDATE from DUAL", it should get me today's date. You may need to use this as part of your query. I understand you are in the midst of a Java program
So, after your query is built at Java area, you need to use the word "SYSDATE" which Oracle understands. I think it can work on other Databases too. But you may check it once.
Hope this helped.

meduri99
Newbie Poster
2 posts since Jul 2006
Reputation Points: 10
Solved Threads: 1
 

Hi, Massod Ali,

Pls try the below query

Select * from tablename where startdate = convert(char,getdate(),103)

Thanks&Regards
Sakthimeenakshi.S

Hi All I want to check whether there is a record present in my database with value: StartDate="Todays's Date" where start date is the column name with datatype DATE.
Sakthimeenakshi
Newbie Poster
3 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

Another way with sysdate is:

select * from table where StartDate = sysdate


or better the following will check only the date without taking into account the hours, minutes:

select * from table where  trunc(StartDate) = trunc(sysdate)


With the first, these dates will be unequal:27/07/2009 12:00:00 , 27/07/2009 12:00:01

but with the second query only the year, month, day will be compared

javaAddict
Nearly a Senior Poster
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 

Ok, If you want to compare two datetime, you need not to convert the getdate() into date.

Try the below query in SQL Server,

select * from table where startdate = getdate()

I hope, it will be usefull for you...

Thanks & Regards

Sakthimeenakshi.S

Another way with sysdate is:

select * from table where StartDate = sysdate

or better the following will check only the date without taking into account the hours, minutes:

select * from table where  trunc(StartDate) = trunc(sysdate)

With the first, these dates will be unequal:27/07/2009 12:00:00 , 27/07/2009 12:00:01

but with the second query only the year, month, day will be compared

Sakthimeenakshi
Newbie Poster
3 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You