How to create a date in excel - excel

I have excel file with 2 columns, year, and month. The year is given in YYYY format and the month the full name of the month like January, February.
Data sample,
column1, Column2
2014, January
2014, February
2018, March
As of now I have tried below code which is giving the error.
=date(A2, B2, 01)
and it is not returning any date values.
Requesting your assistance.
It will also work for me if it is solved by sas code.

Try:
=DATEVALUE(CONCATENATE(B3," 1, ",A3))
This will concatenate the month, follow by a 1 and the year (ex: January 1, 2014). It will then convert this to a datevalue (dates are stored as numbers in Excel). If you format your cell as a date (MMMM YYYY) you will have the desired result.

Try following
=DATEVALUE("1-" & LEFT(B1,3) & "-" & A1)

If you were importing the data into SAS, here is a solution to create a date from month name and year variables.
data have;
length month $ 15;
infile datalines delimiter=',';
input year month $;
datalines;
2014, January
2014, February
2018, March
;
Run;
Data want(keep=date);
Set Have;
/*Length mon $3 yr $4 dt $15;*/
/*Mon=substr(month,1,3);*/
/*Yr=put(year,4.);*/
/*Dt=cats('01',mon,yr);*/
/*Date = input(dt,date9.);*/
/* All in one line */
Date = input(cats('01',substr(month,1,3),put(year,4.)),date9.);
Format DATE mmddyy10.;
Run;

Related

Excel Formula caculating number days of year between 2 dates

I am looking for an excel formula to calculating the number of days from years between "Start date" & "end date"
Example :
My start date is 06/19/2020
My end date is 06/20/2023
I would to know on this example the number of days from year 2020 => from start date ; year 2021 (full year) ; year 2022 (full year) ; 2023 => from end date
Result :
number of days of 2020 : 195
number of days of 2021 : 365
number of days of 2022 : 365
number of days of 2023 : 170
in my databse i have different start date and end date by line to x year
Thanks for your help
You can simply substract one cell value from another, if for example:
A1 = TODAY() (which returns today's date)
A2 = 1/01/2019
B1 = A1-A2 = 765 days
Hope it was helpful for you
You might be interested in the DATEDIF function:
https://stackoverflow.com/a/73268311/13406526
Sorry, but I'm a newbie, cannot add comments.

Convert sting in datetime like excel format cell does in t-sql

I have END_Date data like 43830.99931. When I paste it in the excel and format the cell to Date. It convert it to 12/31/2019 11:59:00 PM. I want same functionality in T-SQL. How can I achieve same result using T-SQL?
Excel (by default) uses the 1900 date system. This simply means that the date 1 Jan 1900 has a true numeric value of 1, 2 Jan 1900 has a value of 2 etc. These values are called "serial values" in Excel and it is these serial values that allows us to use dates in calculations.
The code to convert:
DECLARE #SerialDate FLOAT;
SET #SerialDate = 43830.99931;
SELECT CAST(#SerialDate - 2 AS DATETIME);
returning back the date time value of:
2019-12-31 23:59:00.383
You may have noticed the -2 in the cast. That's because Excel, due to issues with 29th Feb 1900 and the inclusiveness of the start/end dates. (1900-01-01 is day 1 not day 0, and 1900 was not a leap year but excel calculates it wrongly) we have to subtract 2. Details on that issue can be found here.

Calculate in Excel Sum of Days given 2 date ranges (Start date , End date), aggregate monthly

Please find the excel data.
Input format:
ID Begin Date End Date Comment
1 07/25/17 08/16/17 July 6 days, August 16 days
2 05/01/17 05/11/17 11 Days in May
3 07/10/17 07/16/17 6 days in July
Output format:
Jan-17 Feb-17 Mar-17 Apr-17 May-17 Jun-17 Jul-17 Aug-17..... Dec
11 12 16
How to get this aggregate at month level, given a range
Input Format:
Output format:
Are you including start date and end date because your results aren't consistent. If ID2 is 11 days then shouldn't ID3 be 7?
Assuming that you want to include both start date and end date then you can do that like this:
Put the first of each month in A8 copied across (formatted as mmm-yy) then use this array formula in A9
=SUM(TEXT(IF($B2:$B4="",0,IF($C2:$C4>EOMONTH(A8,0),EOMONTH(A8,0),$C2:$C4)-IF($B2:$B4<A8,A8,$B2:$B4)+1),"0;\0")+0)
confirm with CTRL+SHIFT+ENTER and copy across
This only counts rows that have both start and end date
See screenshot:

How to get Quarters for financial year based on date

I'm trying to display quarters based on the financial year: Q1 starting in April, Q2 from July, etc.
In column B there is a list of dates, and in column A I want the corresponding quarter & year. There are 2 parts I can't figure out:
currently for 01 JAN 2018 it shows Q4 2018. Although the date is 2018, it's the final quarter of 2017 and should show Q4 2017
how to get the display format like Q1 17/18 (eg)
At the moment I have:
=CHOOSE(INT((MONTH(B1)-1)/3)+1,"Q4","Q1","Q2","Q3") & " " & YEAR(B1)
Is it possible without any helper columns?
Subtract a Boolean expression from the Year part:
YEAR(B1) - (MONTH(B1)<4)
If the MONTH is Less than 4 it will subtract 1 from the year, otherwise it will subtract 0:
=CHOOSE(INT((MONTH(B1)-1)/3)+1,"Q4","Q1","Q2","Q3") & " " & YEAR(B1) - (MONTH(B1)<4)

Change the date to fiscal year

I want to write a function in Excel to change the date. The logic is like this: if the month is (Jan, Feb or March) the result show me one year past (-1 year) and if the month is (April to -December) the result show the current year (which year the date shows).
example: if date is 02,Jan,2012 the result show me 2011 else show me 2012.
=IF(MONTH(G3) >=4, YEAR(G3), YEAR(G3) - 1) where G3 is the date to test, is one way.
Please try:
=IF(OR(MONTH(A1)=1,MONTH(A1)=2,MONTH(A1)=3),2011,2012)
With 02-Jan-2012 in A1 try,
=YEAR(A1)-(MONTH(A1)<4)
For a full date use one of these,
=DATE(YEAR(A1)-(MONTH(A1)<4), MONTH(A1), DAY(A1))
=EDATE(A1, -(MONTH(A1)<4)*12)
To extract fiscal year use:
=YEAR(A1) + IF(MONTH(A1)>=4,1,0)
I think in your case you would need:
=YEAR(A1) - IF(MONTH(A1)>=4,0,1)
If the months is before 4th month then subtract 1 year, else keep the same year. I wouldn't convert it to a full date DD/MM/YYYY with a 1 year subtracted, to avoid confusion keep it as year only YYYY.
Already plenty of answers, but thought I'd throw another one up:
=YEAR(DATE(YEAR(A1),MONTH(A1)-3,DAY(A1)))

Resources