Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting Day of Week as an Integer with Netezza SQL

Tags:

sql

netezza

This should be doable, but how can I extract the day of the week from a field containing data in date format with Netezza SQL? I can write the following query:

SELECT date_part('day',a.report_dt) as report_dt FROM table as a

but that gives me the day of the month.

thanks for any help

like image 521
user1205546 Avatar asked Feb 12 '12 19:02

user1205546


People also ask

What are the commonly used date functions in Netezza?

Below are the some of the commonly used Netezza date functions. Returns the interval between two timestamps. Used to calculate the exact age. If you specify a single argument, the function returns the interval between the current time and the specified timestamp Truncates the date specified for date to the precision specified by units.

How to get day of week in SQL Server?

How To Get Day Of Week In SQL Server? Sometimes we need to get the day of week in name or number. SQL Server has a couple of inbuilt functions to get the day of week from the given date. To get the name of the day of week, you can use DATENAME function and to get the number of the day of week, you can use DATEPART function.

What is interval support in Netezza SQL?

IBM® Netezza® SQL interval support is nonstandard. Extracts the subfield represented by units from the date/time value, interval, or duration specified for col .

How to get the day of week in name or number?

Sometimes we need to get the day of week in name or number. SQL Server has a couple of inbuilt functions to get the day of week from the given date. To get the name of the day of week, you can use DATENAME function and to get the number of the day of week, you can use DATEPART function. Example.


2 Answers

The below queries give day numbers for any week,month,year for a particular date.

--Day of Week 
SELECT EXTRACT(dow FROM report_dt) FROM table;
--Day of Month
SELECT DATE_PART('day', report_dt) FROM table;
--Day of Year
SELECT EXTRACT(doy FROM report_dt) FROM table;
like image 94
Teja Avatar answered Oct 04 '22 15:10

Teja


Netezza is just ANSI SQL, originally derived from PostgreSQL. I'd expect this to work.

select extract(dow from a.report_dt) as report_dt
from table as a

Returns values should range from 0 to 6; 0 is Sunday. You might expect that to be an integer, but in PostgreSQL at least, the returned value is a double-precision floating point.

like image 39
Mike Sherrill 'Cat Recall' Avatar answered Oct 04 '22 17:10

Mike Sherrill 'Cat Recall'