I need get Monday of last week E.g
Today is 28/11/18 (wednesday)
I need get 19/11/18 (monday)
I know that I can obtain Monday of the current week with
val monday = DateTime().withDayOfWeek(DateTimeConstants.MONDAY)
I get it!
DateTime().withWeekOfWeekyear(
DateTime().weekOfWeekyear-1)
.withDayOfWeek(DateTimeConstants.MONDAY)
I only have to get the week of the year and subtract one week and that is all
Related
I have a week number of year in ISO format and I want to get start date of this week in Hive. First date of week is Monday.
Example: year 2020 week 50 - start date should be 2020-12-07
Try the code below, where year and week are the corresponding column names of your table.
select date(
from_unixtime(
unix_timestamp(concat(year,'-',week,'-','1'), 'yyyy-w-u')
)
) from <your_table_name>;
How can I get the exact week number if my date range is from Friday to Thursday nextweek?
I used this code
datepart(wk,t.date) as workweek
but the week number is different, maybe because the format that I want to get is from Friday to Thursday nextweek. I hope somebody can answer. TIA!
SET DATEFIRST 5; -- Set Friday as first day of the week
Select datepart(wk,t.date) -1 as workweek
From yourTable as t
Why when I run
select (EXTRACT(WEEK FROM current_date)::int )
The output is 6 - why?
Today is 2016-02-14 which is the 8th week since the start of this year.
Am I getting this result wrong?
I'm looking for a function which I give it date and it tells me what week of the year this date is.
The documentation is pretty clear on the calculation:
week
The number of the ISO 8601 week-numbering week of the year. By
definition, ISO weeks start on Mondays and the first week of a year
contains January 4 of that year. In other words, the first Thursday of
a year is in week 1 of that year.
In the ISO week-numbering system, it is possible for early-January
dates to be part of the 52nd or 53rd week of the previous year, and
for late-December dates to be part of the first week of the next year.
For example, 2005-01-01 is part of the 53rd week of year 2004, and
2006-01-01 is part of the 52nd week of year 2005, while 2012-12-31 is
part of the first week of 2013. It's recommended to use the isoyear
field together with week to get consistent results.
Weeks start on a Monday, so Sunday is the end of a week (and "today" is Sunday where I am and in most of the world at this particular time). Also, the first week depends on the when the year starts.
Hi!
I have a dataset with id:chararray and date:chararray. Now, I want to filter out the dataset to those rows which start with:
If the first day of the current month is Sunday, pick all the Sundays of the current month only.
Otherwise pick the last Sunday of the previous month and all the Sundays of the current month.
So, for given below set
12456, 27-04-2014 (last Sunday of the previous month)
33578, 29-04-2014 (not Sunday)
43789, 04-05-2014 (Sunday)
57689, 06-05-2014 (not Sunday)
67890, 11-05-2014 (Sunday)
67845, 13-05-2014 (not Sunday)
57689, 18-05-2014 (Sunday)
33578, 25-05-2014 (Sunday)
The output would be
12456, 27-04-2014 (last Sunday of the previous month)
43789, 04-05-2014 (Sunday)
67890, 11-05-2014 (Sunday)
57689, 18-05-2014 (Sunday)
33578, 25-05-2014 (Sunday)
So, is there a way I can easily get to find the Sundays of the current month and if the first day of the month is not Sunday pick the last Sunday from previous month.
I have all the Date functions available for me like DaysBetween and GetDay in Pig.
From Apache PIG: Get the day of the week and split accordingly
(DaysBetween(ToDate('03-10-2013','dd-MM-YYY'),ToDate(0L)) + 4L) % 7
You can then filter on the returned value
How do I write query if I want 1st day of the month falls in 1st week. my report needs to show data from SUN-SAT.so,
if I run the report on anyway current week, it should only show the data for the previous week from SUN-Sat.
Even though 10/27 falls in the 5th week of October , I am required to show as 10/27- 11/02 falls in the first week of November since November 1 falls in the first
week of November.
Here it is how I want to display the date-range in my report for the month of November. and the same logic applies
for every month.
Week 1 10/27 to 11/02
Week 2 11/03 to 11/09
Week 3 11/10 to 11/16
Week 4 11/17 to 11/23
Week 5 11/24 to 11/30
so, I am not counting till 4th week of October not the 5th one because I am counting 5th week as week 1 for
November.
like wise, the first week of JAN will be 12/29 till 01/04 . I don't want to count 5th week of December because if
I count, there will be duplication.
Thank you. I appreciate it.
In simpler terms, an entire week 'belongs' to a specific month based on whatever month the Saturday of that week lies in. Then you want to work backwards and calculate for a given month, the set of all weeks that belong to that month.
This will give you the forward calculation:
declare #date date = getdate();
select month(dateadd(day,7+datediff(day,#date,'2000-01-01')%7,#date))
And the reverse calculation:
declare #year int = 2013
declare #month int = 11
select
datefromparts(#year,#month,1) as month,
dateadd(day,i*7+datediff(day,datefromparts(#year,#month,1),'2000-01-01')%7-6,datefromparts(#year,#month,1)) week_start,
dateadd(day,i*7+datediff(day,datefromparts(#year,#month,1),'2000-01-01')%7 ,datefromparts(#year,#month,1)) week_end
from (values(1),(2),(3),(4),(5)) wk(i)
I use datediff(day,#date,#known_date) instead of datepart(dw,#date) because it is deterministic.