Number of Days in a month HIVE [duplicate] - sql

This question already has answers here:
Find last day of a month in Hive
(6 answers)
Closed 1 year ago.
Can someone let me know a simple way to get # of days in a month in HIVE SQL based on current_date.
e.g. 2021-02-16 = 28 days, 2021-06-30 = 30 days etc

Use
day(last_day(current_date))
last_day(date) returns last day date, day(date) returns day part of the date, int
See manual here: Language Manual - Date Functions

Related

Previous Workday in Where Clause [duplicate]

This question already has answers here:
How to get Previous business day in a week with that of current Business Day using sql server
(8 answers)
Select the previous business day by using SQL
(3 answers)
Closed 3 months ago.
How do I obtain the previous working date in a where clause
without doing the following and changing this manually
WHERE date = GETDATE()-1
The date column is datetime but I just need the date too.

Exclude weekends [duplicate]

This question already has answers here:
create custom function for date difference excluding weekends and holidays in oracle sql
(1 answer)
Oracle: Days between two date and Exclude weekdays how to handle negative numbers
(2 answers)
Closed 4 years ago.
I am trying to calculate the days between two different dates. If d1 is on saturday or sunday it should not take calculate those days. d2 is the system date.
the formula i have is
(ROUND((d2-d1)-DECODE(SIGN(TO_CHAR(d2,'D')-
TO_CHAR(d1,'D')),-1,2,0)+DECODE(TO_CHAR(d1,'D'),7,1,0)-
DECODE(TO_CHAR(d2,'D'),7,1,0),2)) AS "DAYS",
this would give me 1 days from friday to sunday which is correct, but 7 days from sunday to last sunday instead of 5. anyway i can improve on this formula, or is there a simpler one i can use?

SQL Server Calculate Number of date in a Year [duplicate]

This question already has answers here:
how to get a year and day of the year by using sql server
(2 answers)
Closed 7 years ago.
How do I extract the number of days in a year base on a field in SQL?
For example: I have a Date field in SQL Server
Date
1/4/2015
2/1/2015
2/21/205
I want to use that date field to get me the day out of 365 so the result would look like this
Day of 365 Date
4 1/4/2015
32 2/1/2015
52 2/21/205
Thanks
very useful DATEPART function has overload for day, week, day of week, day of year, quater and others
select DATEPART(DAYOFYEAR, [DATE]) as DayOfYear, [DATE]
DayOfYear can be 366 in case of leap year (e.g. 31 December of 2000)
Have a look at DATEPART()
SELECT DATEPART(DAYOFYEAR , '1/4/2015')

Compare a datetime field within 2 hours [duplicate]

This question already has answers here:
SQL: Get records created in time range for specific dates
(3 answers)
Closed 8 years ago.
I have a table with the field ENTERED_ON (with both date and time value). I want to write a query that return records that have ENTERED_ON value that is past 2 hours comparing to current date time.
For example, if entered_on is 2014-05-06 11:00AM, and currently it's 2014-05-06 2:00PM, I would like to return all records that past the 2 hours when comparing to current date time.
You can write query using INTERVAL. It will looks like
SELECT * FROM Table WHERE `ENTERED_ON` > DATE_ADD(NOW(), INTERVAL -2 HOUR)

SQL last month date of given date [duplicate]

This question already has answers here:
Get the last day of the month in SQL
(22 answers)
Closed 9 years ago.
i am using sql
How to get the last day of the month for a given date
01/03/2014 should return 01/31/2014
I only need the date part.. Thanks
For SQL-SERVER, try this:
SELECT convert(varchar,(DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,'01/03/2014 ')+1,0))),101)