Query for selecting between January to current date ?

Database

Query for selecting between January to current date ?

Hi TD Gurus,

 

I am new to Teradata, I need to right a query which pull data from Januray to current date.If I enter tomarrow dates data should display from Jaunary to tomorrows date.

Please hel me to right a query.Data 

 

Thanks in advance !!

6 REPLIES
N/A

Re: Query for selecting between January to current date ?

you are not very informative with your question but try this:

 

 

select * 
from sys_calendar.calendar
where extract(year from calendar_date) = extract(year from current_date) 
and calendar_date <= current_date
;
N/A

Re: Query for selecting between January to current date ?

You can utilize TRUNC to get the first day of a year:

WHERE datecol BETWEEN TRUNC(CURRENT_DATE, 'YEAR') AND CURRENT_DATE
N/A

Re: Query for selecting between January to current date ?

Hi Dieter, nice one

- is this a hidden feature? 

15.1 documentation isn't mentioning DATE

 

"

TRUNC Purpose

Returns numeric_value truncated places_value places to the right or le of the decimal point.

...

Argument Types and Rules

Expressions passed to this function must have the following data types:

  • numeric_value = BYTEINT, SMALLINT, INTEGER, BIGINT, DECIMAL/NUMERIC, FLOAT/REAL/DOUBLE PRECISION, or NUMBER

  • places_value = NUMBER

"

 

 

N/A

Re: Query for selecting between January to current date ?

Hi Ulrich,

you looked in the wrong place, there's another TRUNC(Date) in DateTime and Interval Functions and Expressions :-)

N/A

Re: Query for selecting between January to current date ?

lol - the joy of overloaded function definitions....

sp2
N/A

Re: Query for selecting between January to current date ?

if you are looking for jan of this year till tomorrow then use below

 

where 1=1

and extract(year from datefield) = extract(year from current_date)

and datefield < current_date +1