Here are some useful date functions I tend to use:
--first of this year
select date_trunc('year', CURRENT_DATE)
--how to get first of the month given a date
select date_trunc('month', current_timestamp)
--how to display monthname-YYYY format - ie December-2012
select trim(to_char(now(),'Month')) || '-' || year(current_date);
-how to display YYYY-MM format - ie 2012-12
select TO_CHAR(current_date,'YYYY-MM');
--truncate timestamp given a date
select date(current_timestamp)--this does not require SQL Extension Toolkit
or
select date_trunc('day', current_timestamp) --requires SQL Extension Toolkit
--select next Monday's date based on today's date
select next_day(DATE(current_timestamp), 'Monday') --if your date is a timestamp and you just want the truncated date for next monday
select next_day(current_date, 'Monday')--if your date is a truncated date
--subtract 1 month from today's date
select date(current_date - cast('1 month' as interval));
--add 6 days from today's date
select date(current_date + cast('6 days' as interval))
or
select current_date - 7
--if you have a timestamp column and want to subtract say 5 days
select date(yourtimestampcolumn) - 5
or
select current_date - 7
--if you have a timestamp column and want to subtract say 5 days
select date(yourtimestampcolumn) - 5
select EXTRACT (DAY FROM DateCol1 -DateCol2) as difference_in_days
from tableA
limit 100;
OR
-- epoch returns number of seconds
select EXTRACT(epoch FROM DateCol1 -DateCol2)/86400 as difference_in_days
from TableA
limit 100;
--Difference in hours between 2 dates (epoch returns number of seconds)
select EXTRACT(epoch FROM DateCol1 -DateCol2)/3600 as difference_in_hours
from TableA
limit 100;
--for those of you who are used to SQL SERVER's datepart function, you are in luck!
select date_part('day', current_date) as day_of_month, date_part('week', current_date) as week_of_year
--Add 1 hour to a timestamp
select current_timestamp, current_timestamp + cast('1 hour' as interval)
--Add 1 hour to a date
select TO_CHAR(datetime(date('2013-02-26') + cast('1 hour' as interval)),'YYYY-MM-DD HH24:MI:SS')
GREAT STUFF, helped me out big time :)
ReplyDeleteThanks for the efforts on gathering useful content and sharing here. You can find more question and answers on Netezza database in the following forum.
ReplyDeleteNetezza database question and answers
Great... thanks!!
ReplyDeleteThankyou so much you saved my time.
ReplyDeleteGood post. I wish the Netezza user guide had some good examples. Very helpful, thanks to you and google :)
ReplyDeleteThanks! You saved my day!
ReplyDeleteIts a great collection on Netezza Database. Can you create a post on difference between DB2 Database and Netezza Database? It would be very useful one!
thanks, same input as previous, you saved my day. this a great page with examples.
ReplyDeleteThank you so much...
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI need to get the name of the day from weekdate in netezza. For eg. 04/25/2014 should return me friday. any suggestions?
ReplyDeleteDifference between two time-stamp in should be in the format of decimal value.
ReplyDeleteNetezza Database
Eg:
select TO_TIMESTAMP('2014-02-19 12:00:00','yyyy-mm-dd hh24:mi:ss') - TO_TIMESTAMP('2014-02-03 00:00:00','yyyy-mm-dd hh24:mi:ss')
Current Output: 16 days 12:00:00
Expected output; 16.5
Please help me out.
select CAST(EXTRACT(EPOCH FROM TO_TIMESTAMP('2014-02-19 12:00:00','yyyy-mm-dd hh24:mi:ss') - TO_TIMESTAMP('2014-02-03 00:00:00','yyyy-mm-dd hh24:mi:ss')) AS FLOAT) / (60*60*24);
DeleteThanks........
DeleteWonderful information, it is very helpful, thank you. Does anyone know if something like this exists out there for working with the time portion of a time stamp. I.E. spliting off hour as an attribute.
ReplyDeletethanks a lot for the information.highly helpful to me to calculate the previous year by providing the following parameter
ReplyDeleteselect date(date('29/05/2013') - cast('1 year' as interval));
Tranks a lot bro!!!
ReplyDeleteI cannot thank enough! :)
ReplyDeleteHow to add two time columns in netezza?
ReplyDelete@Yogesh: Take one time and divide it by 1 then netezza will allow it to add. :)
ReplyDeleteThanks a lot for this awesome blog. It was such a savior for me.
ReplyDeleteGreat stuff. Thanks a lot for writing
ReplyDeleteExcellent Blog, I appreciate your hard work, it is useful
ReplyDeleteTableau Online Course
hi, i am using this formula: TIMESTAMPADD(SQL_TSI_YEAR, -1, VALUEOF("Yesterday") could you advise the equivalent formula in Netezza environment please ?
ReplyDeleteHOW DO I GET JULIAN_DAY OF DIFFERENCE BETWEEN 2 TIMESTAMP DATES? HELP PLEASE
ReplyDeletehow can i get business days (or) work dats count between 2 dates? thanks
ReplyDeleteMalatya
ReplyDeleteKırıkkale
Aksaray
Bitlis
Manisa
U5RK7
Afyon
ReplyDeleteAntalya
Erzurum
Mersin
izmir
PYWX
kars
ReplyDeletesinop
sakarya
ankara
çorum
7PU78
https://istanbulolala.biz/
ReplyDeleteQWS4
4EBFF
ReplyDeleteDenizli Şehir İçi Nakliyat
Urfa Lojistik
Rize Evden Eve Nakliyat
Mamak Boya Ustası
Manisa Şehir İçi Nakliyat
Gümüşhane Evden Eve Nakliyat
Ordu Parça Eşya Taşıma
Trabzon Evden Eve Nakliyat
Bursa Şehir İçi Nakliyat
2014C
ReplyDeleteBitci Güvenilir mi
Mersin Evden Eve Nakliyat
Aydın Şehirler Arası Nakliyat
Çerkezköy Oto Elektrik
Aydın Parça Eşya Taşıma
Shibanomi Coin Hangi Borsada
Tekirdağ Şehirler Arası Nakliyat
Siirt Evden Eve Nakliyat
Huobi Güvenilir mi
47280
ReplyDeleteUrfa Şehir İçi Nakliyat
Kırklareli Şehir İçi Nakliyat
Muş Parça Eşya Taşıma
Gümüşhane Lojistik
Keçiören Boya Ustası
Muğla Lojistik
Coinex Güvenilir mi
Diyarbakır Parça Eşya Taşıma
Çerkezköy Oto Lastik
E4089
ReplyDeleteAntep Evden Eve Nakliyat
Kars Şehir İçi Nakliyat
Silivri Çatı Ustası
Manisa Evden Eve Nakliyat
Paribu Güvenilir mi
Ankara Şehirler Arası Nakliyat
Düzce Parça Eşya Taşıma
Gümüşhane Şehir İçi Nakliyat
Malatya Şehirler Arası Nakliyat
C34ED
ReplyDeleteEryaman Alkollü Mekanlar
Ünye Organizasyon
Karaman Evden Eve Nakliyat
Hakkari Evden Eve Nakliyat
Silivri Duşa Kabin Tamiri
Sinop Evden Eve Nakliyat
Tunceli Evden Eve Nakliyat
Bitmex Güvenilir mi
Binance Güvenilir mi
83FAC
ReplyDeleteİstanbul Şehirler Arası Nakliyat
buy steroid cycles
Erzincan Parça Eşya Taşıma
Kalıcı Makyaj
Kayseri Lojistik
clenbuterol for sale
Eskişehir Şehirler Arası Nakliyat
Bitfinex Güvenilir mi
Aydın Şehir İçi Nakliyat
702C5
ReplyDeleteEryaman Fayans Ustası
Tekirdağ Boya Ustası
Ünye Oto Lastik
Ünye Yol Yardım
Giresun Evden Eve Nakliyat
Muğla Evden Eve Nakliyat
Kastamonu Evden Eve Nakliyat
Çerkezköy Çamaşır Makinesi Tamircisi
İzmir Evden Eve Nakliyat
B9CEA
ReplyDeletekomisyon indirimi %20
F4B8E
ReplyDeleteCoin Kazma Siteleri
Bitcoin Kazanma Siteleri
Coin Kazanma Siteleri
Bitcoin Madenciliği Nasıl Yapılır
Kripto Para Nasıl Üretilir
Okex Borsası Güvenilir mi
Bitcoin Üretme
Coin Kazanma
Coin Nasıl Alınır
FE150
ReplyDeleteCoin Kazanma Siteleri
Coin Nedir
resimli
resimlimagnet
Kripto Para Kazma
Coin Üretme
Binance Madencilik Nasıl Yapılır
Kripto Para Madenciliği Siteleri
Binance Madenciliği Nedir
7CA9B
ReplyDeleteCoin Nedir
Coin Madenciliği Nedir
Coin Nasıl Alınır
Bitcoin Üretme
Bitcoin Oynama
Gate io Borsası Güvenilir mi
Coin Üretme Siteleri
Binance Neden Tercih Edilir
Yeni Çıkan Coin Nasıl Alınır
A89C5
ReplyDeleteresimlimagnet
F4996
ReplyDeleteResimli Magnet
DB341
ReplyDeletebinance referans kodu
resimli magnet
referans kimliği nedir
binance referans kodu
referans kimliği nedir
binance referans kodu
resimli magnet
binance referans kodu
resimli magnet
F31B6
ReplyDeleteamiclear
CCED8
ReplyDeletesightcare
C174E
ReplyDeleteThreads İzlenme Satın Al
Parasız Görüntülü Sohbet
Loop Network Coin Hangi Borsada
Bone Coin Hangi Borsada
Bitcoin Madenciliği Nasıl Yapılır
Pepecoin Coin Hangi Borsada
Tiktok Takipçi Hilesi
Coin Madenciliği Siteleri
Keep Coin Hangi Borsada
B8012
ReplyDeletebitbox
aave
chainlist
sushi
phantom
yearn
ledger live
onekey
dextools
C2515
ReplyDeletebinance
binance
mexc
telegram kripto kanalları
kizlarla canli sohbet
bitexen
en iyi kripto para uygulaması
binance ne demek
kraken
7F522
ReplyDeletebinance referans kod
4g proxy
bitexen
gate io
bitrue
bitexen
coin nasıl alınır
btcturk
bingx
964A2
ReplyDeletepapaya
telegram kripto para grupları
bitmex
bitcoin hangi bankalarda var
filtre kağıdı
gate io
kripto telegram grupları
mercatox
en güvenilir kripto borsası
B4AF9
ReplyDeletereferans kimliği
binance 100 dolar
kızlarla canlı sohbet
bitcoin hangi bankalarda var
kraken
sohbet canlı
bitcoin seans saatleri
binance
bitget
A582D
ReplyDeletebitexen
bingx
kripto para nereden alınır
poloniex
mobil proxy 4g
paribu
bitrue
telegram kripto para kanalları
bitcoin giriş
74107
ReplyDeletegüneş enerjisi fiyatları
dedicated server
seo
fuar standı
jeneratör fiyatları
4g mobil proxy
jeneratör fiyatları
güneş paneli
iç mimar
1A8D8
ReplyDeleteFooter Link
Google Yorum Satın Al
Hosting Satın Al
Metin2 Pvp Serverler
adwords hesap satışı
Youtube Kanal Satın Al
İş İlanları
SEO Ajansı
google 5 yıldız
05540
ReplyDeleteRad Coin Yorum
Ens Coin Yorum
Neo Coin Yorum
Rlc Coin Yorum
Waxp Coin Yorum
Tfuel Coin Yorum
Bat Coin Yorum
BTC Son Dakika
Loom Coin Yorum
13773
ReplyDeleteZec Coin Yorum
Gtc Coin Yorum
Dgb Coin Yorum
Xno Coin Yorum
Dai Coin Yorum
Chz Coin Yorum
Kda Coin Yorum
Cudos Coin Yorum
Bitcoin Forum
C0940DAAA0
ReplyDeleteinstagram takipci satin al
BE6FE344B6
ReplyDeleteinstagram takipçi paketi
D29927AE84
ReplyDeletetelafili takipçi satın al
Rise Of Kingdoms Hediye Kodu
Whiteout Survival Hediye Kodu
Roblox Şarkı Kodları
Brawl Stars Elmas Kodu
Kaspersky Etkinleştirme Kodu
Whiteout Survival Hediye Kodu
Kaspersky Etkinleştirme Kodu
Pubg New State Promosyon Kodu