I want to derive a column for day of week for a time value. There are DAY_OF_MONTH and DAY_OF_YEAR functions in Contour, but not one for day of week.
How can I derive the day of the week using Contour?
There is currently no DAY_OF_WEEK function, but you can use this workaround:
date_format("<NameOfYourDateColumn>", 'EEE')
Related
I want to extract week from datetime, the output I want is 'YY/week', where week is the week of the year (eg '201724' is the 24th week in 2017).
The term "week of the year" is too ambiguous.
The week may start from Sunday, Monday or another weekday
The weeks enumeration in the year may start from 0 or 1
The weeks enumeration in the year may start from the week which includes January, 1 (and hence may be partial) or from first complete week of the year
The last week of the year, if it is partial, may be counted or not
Each DBMS has its own functions (sometimes original, always with original names) that can return the number of the week in the year on a given date. But they can not always take into account the above features.
Important addition provided by jarlh:
ISO 8601 (#4.3.4):
The first calendar week of a year is the one that includes the first Thursday of that year.
The last calendar week of a calendar year is the week immediately preceding the first calendar week of the next calendar year.
Week 1 is the first week of a year.
A calendar week starts on a Monday.
ISO 9075 doesn't even mention weeks.
SELECT TO_CHAR(TO_DATE('19-FEB-22') , 'IW') from DUAL;
To get the corresponding four-digit year, use
SELECT TO_CHAR(TO_DATE('19-FEB-22'), 'IYYY') FROM DUAL;
TO_CHAR() having so many options like this read more in Oracle manual or extract portation of date Extract Portion of Date Time Value
OutPut
You can use the following Mysql type query to extract.
SELECT DATE_FORMAT(BirthDate, " %u %Y") FROM Employees;
where the BirthDate date column in the database and the Employees is the table name.
This will result
49 1968
08 1952
35 1963
Week and the year.
in postgresql:
SELECT to_char('2016-12-31 13:30:15'::timestamp without time zone, 'yy/ww') ;
result:
16/53
I have a table in access, which has a contract start date, contract end date.
It also needs auto filled columns for the start and end date of each year between the contract start and end dates.
E.g, customer takes out 5 year contract.
01/01/2020 - 01/01/2025
Year 1’s end date would be 1 year, minus a day from the contract start date:
31/12/2020.
As mentioned, this needs to be written as an expression in Microsoft Access.
I can’t find info on multiple date calculations from a singular start date (DateAdd etc).
Thanks for any help
Use DateAdd in code (or query):
UltimoYear = DateAdd("d", -1, DateAdd("yyyy", 5, DateStart))
Replace 5 with 1 for one year.
Given a table with two dates and a date interval (i.e. 6 WEEKS), how can I count how many times this interval fits in this date interval?
In my PHP script I'm using a simple for loop, but I'd like to add this in a MySQL query.
A simple calculation would be to count the number of days between the dates and then assume a month has 30 days and a year has 365 days, but that's not always true.
How can I calculate with datediff and a date interval string?
When I understood you correctly, you need the timestampdiff() function.
The first parameter is the unit of the interval. The result is how many units are between the two dates.
Consider given 2 dates between 2015-01-01 and 2015-01-30, I need to find the dates for every Monday and every Sunday during that period.
I have a report, the user needs to select a date range, and from the date range it calculates each first-day-of-week and last-day of week and passes it in that way.
How it currently works in SSRS is
exec storedprocname
#BD=N'798211,798654,798664,798826',
#CGNo=N'47',
#SCGNo=N'4701,4702,4703,4704,4705,4706,4707,4708',
#ProductClass=N'1,2,4,3',
#ProductCode=N'1020',
#Region=N'772',
#FirstDayOfWeek='2014-01-06 00:00:00',
#LastDayOfWeek='2014-01-12 00:00:00'
User selects multiple Mondays and Sundays, the report is a matrix table and matrix's on first day of week
FirstdayOfWeek = '2014/06/09,2014/06/16'
LastdayOfWeek = '2014/06/15,2014/06/23'
What I need is a date range the user selects this and it will still pass it in the same way
#startdate '2015/01/01' = Thursday (for this select current week's Monday)
#startdate '2015/02/01' = Sunday
You can use SSRS inbuilt function WEEKDAYNAME
=WEEKDAYNAME(DATEPART("dw", Fields!myDate.Value)
OR
=WEEKDAYNAME(DATEPART("w", Fields!myDate.Value)
You can use weekdayname function to filter your dataset or matrix or use in Iff expression.
If you want to handle it in SQL Server you can use dataname function.
I currently have a table in my database which lists a range of dates, going from May until October, in the following format: YYYY-MM-DD
What I would like to do is create a new column with the days of the week, matching the date. I thought of two options;
Update all rows, in column 'day', starting with monday, then the next tuesday, next wednesday, etc, etc. and when reached sunday, loop the sequence until end of table.
Read the date in column 'date' and update the column 'day' with the matching day of the week.
I think option 1 is the most easy, and very well possible, because there are no dates being skipped. But I have no idea how to do this and couldn't find anything similar searching the web.
Any help would be greatly appreciated! Thank you
As a general rule, I would say: don't do it. The day of the week is derived directly from the date; storing it separately in the database breaks one of the basic rules of normalisation (no derived data).
There are MySQL functions to find the day of the week - dayofweek() and weekday().
Try this:
update table
set day = DATENAME(dw, date)