Is there an inbuilt function in SAS that gives the text day of the week? Such as Monday, Tuesday etc from a date variable?
So far, I have just found the weekday function, that just gives the date as a number from 1-7.
If you want to get a text day of the week from a date, you can use DOWNAME. format.
data _null_;
result = put(today(), dowName.);
put result=;
run;
If you want to get a weekday name from a weekday number, I do not know specific function, which does it, but you can use the fact that 1-7 are also dates and 0 is Friday, 1st January 1960 and add 2 to your number:
data _null_;
do day = 1 to 7;
weekDay = put(day + 2, dowName.);
put weekDay=;
end;
run;
Which will give you:
weekDay=Monday
weekDay=Tuesday
weekDay=Wednesday
weekDay=Thursday
weekDay=Friday
weekDay=Saturday
weekDay=Sunday
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 am creating a package which will store a report's generation date. on basis of that date need to derive the next Wwednesday date.
Ex: report date is 11/11/2019 so wed date should be 13/11/2019.
This Derived Column Expression should provide the next Wednesday's date.
DATEADD("DAY",((1 + DATEDIFF("DAY",(DT_DATE)"1/1/1970",GETDATE())) / 7) * 7 + 6,(DT_DATE)"1/1/1970")
Parts (inside out).
Days since 1/1/1970 + 1.
(Divide by 7) (Implicit Cast to Int) (Multiple by 7) will round it to last Thursday.
When added days back to 1/1/1970 (+6 days more) will move to next occurring Wednesday.
Notes
Without the initial 1 day offset, If GETDATE() is a Wednesday, the result will be GETDATE()'s date.
GETDATE() can be swapped out with GETUTCDATE() or a date Variable as needed.
The +6 can be moved back to +5 if a Tuesday is desired.
I want to calculate start date and end date for the particular given week in the month , (assuming my week starts on monday and ends on sunday).
So, What I want is if I select any week number lets say 1,2 ,3 or 4 I should be able to calculate the start date for that particular week and end date .
In addition to the week number for that particular month , I will also give an input of year and month.
selection of year month and week number will be from HTML page through a drop down select option.
And I am looking for some efficient way of doing this .
Use Moment.js
Get the value of week number
var weeknumber = moment("07-27-2017", "MM-DD-YYYY").week(); console.log(weeknumber);
I have a function which applies a rate based on the number of months that an item has been stored. However we charge half that rate if the item was stored after the 15th. The function I'm using to determine the amount of months an item is stored is the DateDiff() Function. It returns the number of months between two dates. How do I determine if the date is before the 15th or after? If I use DateDiff(d,1/1/2015, 4/1/15) I would get a value greater than 15 so I cannot see if the Date is before or after the 15th using greater than or less than 15. How can I determine if either of the dates (entrance date which is the date the item entered into the storage area and the exit date which is the date it is removed) are before or after the 15th?
VBA models a date as an floating point double. The integral part stands for the day. It advances by 1 per day.
It provides a function Day(date) which you can use to extract the day of the month in which date occurs.
For example, CDate(40000) will return you 6-July-2009, and Day(40000) returns you 6.
I would do something like
if format(date, "DD") <= 15 then
msgbox "this is 15 or below"
else
msgbox "this is 16 and above"
end if
You can put a date variable in instead of date which is a built in function to return the system date.
I am trying to capture the Monday" date from a giving date.
so today is 4/10/2014 I need to return 4/07/2014 since Monday was 4/07/2014
and if I do 02/07/2014 it should return 02/03/2014 since it was the last Monday.
How can I do that using MySQL?
thanks
Just use WEEKDAY()
SELECT '2014-04-10' - INTERVAL WEEKDAY('2014-04-10') DAY;
(zero is for monday). Substutute your date instead of 2014-04-10 (but it must be valid date). So: you'll subtract number of days past since last monday.
If given date string isn't in standard MySQL date format, use STR_TO_DATE() to convert it