Thursday, November 7, 2024

Date Functions in SQL


Select Getdate() as CurrentDate;

Select Getdate() -1 PreviousDate;

Select Getdate() +1 NextDate;

Select DATEADD(dd,1,getdate()) as NextDate;

Select DATEADD(mm,1,getdate()) as NextMonth;

Select DATEADD(yy,1,getdate()) as NextYear;

Select MONTH(getdate()) as CurrentMonth;

Select EOMONTH(getdate()) as MonthEndDate;

Select EOMONTH(getdate(),1) as NextMonthEndDate;

Select YEAR(getdate()) as CurrentYear

Select DATEDIFF(dd,getdate(),eomonth(getdate())) as NoOfDaysLeftThisMonth;

Select DATEPART(year, CURRENT_TIMESTAMP) as ExtractingYear;

Select DATEPART(year, getdate()) as ExtractingYear;

Partitioning

Hive organizes the tables into partitions, and partitions are subdivided into buckets. ALTER TABLE table_name ADD [IF NOT EXISTS] PARTITION ...