Formatting date in Excel - excel

How can I easily format "202104" --> 2021/04 in Excel?
My current method is to concatenate the original string with "01" and then change it into a date. However, I am seeking a more efficient format method.
Thanks

Try this.
For Text
=LEFT(A1,4)&"/"&RIGHT(A1,2)
For Date Value
=TEXT(DATEVALUE(LEFT(A1,4)&"/"&RIGHT(A1,2)),"YYYY/MM")

As far as I know, 2021/04 is not a valid date in Excel, but 2021/04/01 (first of April, year 2021) is.
In order to achieve this, you can use this formula:
=DATE(INTEGER(202104 / 100);MOD(202104;100);1)
Where:
1) INTEGER(202104/100) is the integer division of 202104 by 100, calculating the year.
2) MOD(202104;100) means 202104 modulo 100, in order to calculate the month.
3) 1 means the first day of the month.

Related

Difference time view from Excel to VBA

I can't obtain the average time from start to end of some activities,
I tried 1K way but the result isn't correct, every time I've one day minus.
the image can explain better (that my english).
In this example the sum of my activities il 480:52:56 hours, in vba I've different result, for vba the date is "19/01/1900 00:52:56" like 456:52:56 hous
24 hours minus
why this difference? and how I can obtain the same result?
thanks for any suggestion
Dates are stored as serial numbers where first valid date has a value of 1. This value in excel reads as 01/01/1900, and in VBA as 31/12/1899. In excel, value 60 returns 29/02/1900 which doesn't exist in VBA, so from value 61 onwards all values will return the same date in VBA and excel.
/e: Also, maximum value is 2958465 (31/12/9999), values higher than that will return error rather than valid date
thanks to your comments I understand that the problem is for the minor dates of March 1, 1900 so I changed the select from:
Select [DataAttesa] as Data, avg(iif([totHours] > 1 and [totHours] < 61, dateadd("d",-1,CDate([totHours])) , [totHours])) as nr FROM [db_In$] Where TypeTrasp = "AOG" group by [DataAttesa] Order by [DataAttesa]asc
now, when I put the recordset.results on excel the value are correct.
Thank at all

Converting large time format to decimal in excel

I'm trying to convert a large time value in excel to a decimal number for hours.
I currently have a column adding up "Ready time" for a call centre which is 3545:20:02 as a SUM. I now want that to show me the same hours in a decimal format e.g. 3545.333 as it's used in another calculation.
For reference, when I convert the above time to a General excel value, it is 147.7222454.
The formula I've been using is: =IFERROR((DAY(M54)*24) + HOUR(M54) + (MINUTE(M54)/60),0) and has been working fine for smaller time values.
Thanks in advance!
Excel counts in days (1 day = 1) so for hours you just multiply by 24, i.e.
=M54*24
format result cell as number with required number of decimals
[the reason your current formula fails is because of DAY function - DAY is day of the month so it fails for you when the time value is >= 32*24 = 768 hours]

VBA equivalent of DATEVALUE?

The formula function of =DATEVALUE and VBA's DateValue() provide exclusive results. How can I format a date in VBA to obtain the same serialization as I would by using =DATEVALUE?
Example: 1/19/2016, formatted "m/d/yyyy", will return 42388 through =DATEVALUE()
Use CLng e.g.
=DATEVALUE("7/7/16")
Returns
42558
In VBA:
? CLng(DateValue("7/7/16"))
42558
Several ways to do this. #Robin has a good one. I'll add one more
?DateDiff("d",0, "7/7/16")
42558
The DateDiff function calculates the difference between the two dates (2nd and 3rd parameters) in the units of the first parameter. So if you changed "d" to "h" you would get the number of hours between 0 (the first possible date in Excel/VBA) and 7/7/2016

Excel split cost figure between months with partial dates

I have a list of cost figures with start dates and end dates which I need to split between months, I have searched for the solution to this problem but cannot seem to find one that will work with partial months i.e.( startdate:01/01/2015 enddate: 15/04/2015 cost:10000) which would leave figures like Jan:2857, Feb:2857, Mar:2857, Apr:1429.
I have been trying to modify this example: http://www.excel-university.com/excel-formula-to-allocate-an-amount-into-monthly-columns/ but having no luck getting the partial months working.
Any suggestions or help would be most welcome. Thanks in Advance
if you calculate it on daily basis, would it be ok? the result would be:
01.01.2015 01.02.2015 01.03.2015 15.04.2015
2.857,14 2.857,14 2.857,14 1.428,57
your daily amount is:
=10.000/(DAYS360(startdate;enddate;TRUE)+1)
(be carefull of true and false argument)
under the dates or instead of 2.857,14 etc. insert the formula:
=IF(DAY("your date")>1;DAY("your date");30) * daily amount
This formula assumes that you want to have 30 days in each month:
=IF(DAY(01.01.2015)>1;DAY(01.01.2015);30)
result = 30
=IF(DAY(15.04.2015)>1;DAY(15.04.2015);30)
result = 15
so if months begins with a date different from the 1st it will give you the number of days.
if you want to match months with your startdate and enddate (if i understood your comment correctly), you could do:
=IF(OR(
AND(MONTH(startdate)=MONTH(your date);YEAR(startdate)=YEAR(your date));
AND(MONTH(enddate)=MONTH(your date);YEAR(enddate)=YEAR(your date))
);"match";"no match")
by this you make sure that month and year correspond.
If you want to get the number of days in a month automatically, you could use:
=DAY(DATE(YEAR("your date");MONTH("your date")+1;1)-1)
but this does not assume anymore 30 days, you can change it with if statement
I hope this helps,
Best - AB

datedif in excel when the number format is [$-409]d-mmm-yyyy;#

I have two columns with the format [$-409]d-mmm-yyyy;#, I want to calculate the difference of date of these two columns. Please help.
Thanks
The =datedif() formula will do that for you, as per http://www.cpearson.com/excel/datedif.aspx:
=datedif(FirstDate, LaterDate, Interval)
Where FirstDate is the earlier date, LaterDate is the later date, and interval is the return type. I usually use 'm' for months, since this can be divided by 12 to get decimal years. Lots of other options, though.

Resources