cancel
Showing results for 
Search instead for 
Did you mean: 

Insert Today's Date into query

Former Member
0 Kudos

I created a query and want it to filter based on todays date. How do I automatically add todays date to the query so the user does not need to type it in?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Use the getdate() function for todays date. For example, select * from OJDT T0 where T0.refdate >= getdate() will return all the fields for journals posted with today's date.

HTH

Former Member
0 Kudos

select * from OJDT T0 where T0.refdate >= getdate() did not return any documents for me even though it has records with T0.refdate equal to todays date.

I just had to change select * from OJDT T0 where T0.refdate >= getdate()-1 in order to get todays records.

Answers (1)

Answers (1)

Former Member
0 Kudos

Yes you are right. You will need to use WHERE convert(varchar, T0.refdate, 103) = convert(varchar, getdate(), 103)

This is because the getdate() is actually a datetime field and returns current date and current time so in the previous statement you are asking for journal fields where the posting date = todays date AND the exact time that the query is run which is never going to be true.

If you just use getdate()-1 you will also get yesterdays' journals posted after this time yesterday.