BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MustafaAbdelhaq
Calcite | Level 5

Hello,

I have a table which contains multiple columns, one of the columns is call Date_Of and it contains dates in the following format. ddMONyyy:hh:mm:ss Ex. 26MAY2015:00:00:00.

I'm trying to use a query in which I try to extract only records of today.

   SELECT t12.DATE_OF,

      FROM QUERYt12

      WHERE t1.DATE_OF<=today();

QUIT;

Unfortunately the query doesn't extract any records, on the other hand if I switch the < operator to > it extracts all the data.

I think it's related to the format of the date, I could't find a solution to this problem, hope someone will be able to help me out here.

Appreciate your help.

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Assuming t1.DATE_OF is a proper numeric data time value, then it includes date and time.  Today() function returns a date value, i.e. no time.

If you only want to compare dates then:

where datepart(T1.DATE_OF) <= today();

If you want time as well then you need to build a datetime response:

where T1.DATE_OF) <= dhms(today(),hour(time()),minute(time),0);

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Assuming t1.DATE_OF is a proper numeric data time value, then it includes date and time.  Today() function returns a date value, i.e. no time.

If you only want to compare dates then:

where datepart(T1.DATE_OF) <= today();

If you want time as well then you need to build a datetime response:

where T1.DATE_OF) <= dhms(today(),hour(time()),minute(time),0);

MustafaAbdelhaq
Calcite | Level 5

It worked perfectly, thank you so much.

ballardw
Super User

As to the why: Today() returns a number of days since 1 Jan 1960 as are all SAS DATE valued variables. If your variable actually contains a DATETIME value as shown then the value stored is the number of SECONDS.

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore Now →
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2202 views
  • 1 like
  • 3 in conversation