Big Query get first day of week - date

I'm working with Big Query and I need to get first day of week.
For example if date = '2022-08-26' I want to have '2022-08-22' where 22 is Monday.
Any solutions please ?
Thanks in advance.

To achieve this you'll want to use the DATE_TRUNC function as follows:
select date_trunc(date('2022-08-26'), WEEK(MONDAY))
You can change the parameter for WEEK to be any day of the week, default is SUNDAY.
Documentation can be found here:
https://cloud.google.com/bigquery/docs/reference/standard-sql/date_functions#date_trunc

Related

Report Today minus 1 day

need help with this query DB2 IBM
SELECT
ABALPH AS Kunde,
SDLITM AS Artikel,
SDDSC1 AS Beschreibung,
SDSOQS AS Menge, date(digits(decimal(SDIVD+1900000,7,0))) AS Invoice,
decimal(SDUPRC/10000,15,2) AS Einzelpreis,
decimal(SDAEXP/100,15,2) AS Gesamtpreis,
SDDOCO AS Dokument,
AIAC01 AS Region
Now my question is , how can I get the today date minus 1 day ?
Thank you so much
have test it with ADD_DAYS doesn´t work.
I do not see the point in your query where a date is referenced but your query seems incomlete anyways because join contions are missing.
In general you get todays date with current date and you get yesterday with current date - 1 day
Check out this query:
SELECT current date, current date - 1 day
FROM sysibm.sysdummy1
Per the DB2 documentation, ADD_DAYS is valid with negative numbers for previous days. See example 4 on that page. So usage like this should have worked:
ADD_DAYS(DATE(...), -1)
or
ADD_DAYS(CURRENT_DATE, -1)
You should post your specific attempted usage of it and the error that is reported when you try it.

How to calculate the last week of every month?

I've been having a look around but I can't seem to find anything that answers this question. I want to calculate the date for the last week of every month. For example, the date for the last week of April 2021 is 26-04-2021. I want a date, not a week number.
I use Google Big Query, I do have a calendar table I could use to extract year and month.
Thanks,
Emily
Try date_trunc:
SELECT date_trunc(last_day(month1st, month), week(monday))
from unnest(GENERATE_DATE_ARRAY('2021-01-01', '2021-12-01', interval 1 month)) AS month1st;

Mongodb: how can i generate all days base on current month

I'm wondering if anyone has an elegant solution for generating days based on a month selected for use in a dropdown. What i'm wanting to do is for the user to select the month, then populate a dropdown for days for that month. So for example if the user selected january you would have a dropdown list with values 1 - 31. The only bit i think might be tricky will be to do with leap years, so it may need to pass in year as well. Any ideas would be most appreciated :)
for calendar and get day of month use 'moment'
moment("2012-02", "YYYY-MM").daysInMonth() // 29
moment("2012-01", "YYYY-MM").daysInMonth() // 31

SSRS/Report Builder datediff in working days

I have a calculated field in my report that gives me the number of days between two fields. This is in calendar days though.
=DateDiff("d",Fields!Date_Reported.Value,Fields!EventDate.Value)
I have been asked to include number of working days and I'm struggling!
Is it possible to count the number days between these fields using only working days? eg. Monday to Friday in this case?
Thanks in advance for any help.
Try this:
=datediff("ww",Fields!Date_Reported.Value,Fields!EventDate.Value, vbMonday)
+datediff("ww",Fields!Date_Reported.Value,Fields!EventDate.Value, vbTuesday)
+datediff("ww",Fields!Date_Reported.Value,Fields!EventDate.Value, vbWednesday)
+datediff("ww",Fields!Date_Reported.Value,Fields!EventDate.Value, vbThursday)
+datediff("ww",Fields!Date_Reported.Value,Fields!EventDate.Value, vbFriday)
The source

Hive: Subtracting 1 year from current date

I'm trying to find the best way to subtract 1 year and also one month from the current date in a Hive query. Using the following, I don't believe it will take into account leap years or if the fact that months have different amounts of days so eventually the code will break. Any help would be greatly appreciated!
set my_date = from_unixtime(unix_timestamp()-365*60*60*24, 'yyyy-MM-dd');
set my_date = from_unixtime(unix_timestamp()-30*60*60*24, 'yyyy-MM-dd');
Thank!
-Rebecca
If you have date format like yyyy-MM-dd hh:mm:ss in Hive, it is easy to implement using following functions
concat((year(date_field)-1),'-', (month(date_field)-1), '-', day(date_field))
Use IF and CASE functions to implement your logic to find whether it is a leap year or not(by dividing year by 4)