How to convert custom digits to date in excel - excel

Assuming 421 stands for April 2021 and 1299 for December 1999, what would be the correct formula to convert the digits in to the corresponding date format in excel?

Adjust the 30 as you see fit:
=IFERROR(DATE(IF(VALUE(RIGHT(A1,2))<30,2000+RIGHT(A1,2),RIGHT(A1,2)),LEFT(A1,LEN(A1)-2),1),"")

Actually, here is a one-liner (note, to get the correct century the formula is posted lower in the answer and is more complicated):
=DATE(RIGHT(A1,2),LEFT(IF(LEN(A1)=3,0&A1,A1),2),1)
DATE requires 1) Year 2) Month and 3) Day
So, it's easy to get the year (just take the two most digits)
However, it's trickier to get the month, since it can be 3 or 4 digits, so you need some if logic to add a 0 in front if only 3 digits and THEN take the left two digits to extract the month.
Finally, you have to have a day for the formula, so just put a 1. Then format the cells as desired to whatever date format. See screenshot.
In order to get the correct century, then the formula gets complicated :) Basically, it says if the date is greater than now, subtract a century. If it is less than now, then go with that date.
=IF(DATE(YEAR(DATE(RIGHT(A1,2),LEFT(IF(LEN(A1)=3,0&A1,A1),2),1))+100,MONTH(DATE(RIGHT(A1,2),LEFT(IF(LEN(A1)=3,0&A1,A1),2),1)),DAY(DATE(RIGHT(A1,2),LEFT(IF(LEN(A1)=3,0&A1,A1),2),1)))>NOW(),DATE(RIGHT(A1,2),LEFT(IF(LEN(A1)=3,0&A1,A1),2),1),DATE(YEAR(DATE(RIGHT(A1,2),LEFT(IF(LEN(A1)=3,0&A1,A1),2),1))+100,MONTH(DATE(RIGHT(A1,2),LEFT(IF(LEN(A1)=3,0&A1,A1),2),1)),DAY(DATE(RIGHT(A1,2),LEFT(IF(LEN(A1)=3,0&A1,A1),2),1))))

Related

Extract the hour from the h" hour(s) and "m" minute(s)" in excel

I have the list of data that showing the Hours and the Minutes that I extract from the system. I need to be extract the hours.
As example below, column B first row, the Hours would be 64 and the minutes would be 46.
But when I used the formula =Hour , its turn up the different value since its actually decimal number.
Cannot use left() , it will give the actual decimal number.
Updated:
We tried the #harun24HR 's but cannot readable the value.
But if you noticed, if i copy and paste the value is different. thats why the search not applicable.
4th Update:
To Solar Mike, I have tried the formula given from the thread the i think the value not readable
It's a time value which Excel stores as calculated value based on 24 hours = 1.
To retrieve the hours only you can use:
=INT(A2*24)
To retrieve the minutes only you can use:
=(A1-(INT(A1*24)/24))*24*60
Your time value is already a number in time format so you just need it to change it to decimal system. Dates and time values are numbers. Even if you see it as 30/09/2019 or 12:00:00, actually, for Excel, both cases are numbers.
First date Excel can recognize properly is 01/01/1900 which integer numeric value is 1. Number 2 would be 02/01/1900 and so on. Actually, today is 44659.
Now, about your data, you posted this screenshoot:
So the value is numeric, not text/string. In Excel, what you see is not always what you have. Probably that column has been formatted using custom mask. My fake data is like this:
The numeric value is 02/01/1900 16:46:36 (or 02/01/1900 4:46:36 PM it depends on your regional settings) but I've applied a custom format like this:
[hh]" hours" mm " minutes"
So what I have is a number but what I see is a text!
We have to work with the number (to be honest, ist's easier to work with numbers), so to extract the total hours, minutes and seconds.
Formula in B1: =INT(A1*24) total hours
Formula in C1: =INT(A1*24*60-B1*60) total minutes
Formula in D1: =A1*24*60*60-B1*60*60-C1*60 total seconds
This should guide you on whatever are you trying to achieve.
From your current sample data you try-
For hour =LEFT(A2,SEARCH(" ",A2)-1)
For minutes =RIGHT(SUBSTITUTE(A2," minutes",""),2)

How to add month and day to a numbered year in excel?

I have a column of years, 2000, 1990 > 900 (0900) > 1876 etc.... However I needed to have it in a date format e.g. 01/01/2000, 01/01/900 (01/01/0900). I can't work out how to do this. I can only see formulas which add days and months which are already in the format I would like. I only need it as 01/01 to input to QGIS as a csv file.
Dates are represented in Excel by real numbers. The integer part (to the left of the decimal place) is the number of days since 12/30/1899. The fractional part (to the right of the decimal place) is the fraction of the day. .5 = noon, .75 = 6pm, etc. How these numbers appear in the worksheet depends on the number format of the cell. So if your cell value is 36526 (or 1/1/2000) and the number format is "mm/dd/yyyy" you will see '01/01/2000' in the cell. If the number format is "mm/dd", you will see '01/01' in the cell.
I don't understand what you mean by "I only need it as 01/01 to input to QGIS as a csv file" but if you show me some code, and explain how the results you're getting differ from the results you want, I can probably help get you there.

Convert Modified Julian Date to UTC Date in Excel

I am looking for a formula where I can put a 5 digit Modified Julian Date and have it convert it to today's date for me.
I did it in a way where I have a separate sheet with a table but although it works, I am looking for a way without the need of a separate table. Here is some information:
00000 should translate to 11-17-1858
58890 should translate to 02-11-2020
Every time the number goes up 1, it should go up 1 day. This needs to have leap years in consideration as well. Any help will be appreciated.
Here is a website that currently does the conversions:
http://www.csgnetwork.com/julianmodifdateconv.html
This has to be done without macros, literally need it in formula format.
Just subtract 15018 and format the result as a date.
Why 15018 and not 15020?
In Excel, 1-Jan-1900 value is 1
In your date scheme 15020 = 1-Jan-1900
But, if you had the number 15020 to convert and subtracted 15020 it would --> 0, not the desired 1.
Therefore we reduce the 15020 by 1 to 15019.
Next, there is a deliberate "bug" in Excel, widely discussed both on SO and the internet, whereby the year 1900 is erroneously classified as a leap year.
So for any date equivalent that is after 28-Feb-1900, we have to subtract an extra 1.
If you might be dealing with dates between 1/1/1900 and 2/28/1900 you will need to modify the formula to take that into account.

How can I extract the hour part from a duration value in Excel?

How can I convert duration in excel to text ? I am having 1037:00:00 in a cell, which is the sum of certain durations. I want to extract 1037 alone. Excel returns "hours" when I try to extract with MID or use TEXT function.
If it is really the sum of some durations you can get the amount of hours by multiplying the cell by 24. The internal representation of a date or time cell is the number of days since beginning of the year 1900, so you have to multiply it by 24 to get the number of hours. (The year 1900 is not interesting for you as you just want a time span.) The Hour function does not work here because you get the day hour which is 5 in this case.
Be sure to format your target cell as regular number.
lets assume your cell with 1037:00:00 is in cell L40. You can use the following formula to pull the hours.
=INT(L40)*24+HOURS(L40)
Note this will only pull full hours rounded down. It does not take into account minutes or seconds.
Alternatives:
=Rounddown(L40*24,0)
This alternative is what Fratyx explained in his answer.

Converting Julian Date (5 or 4 character) to Gregorian and vice versa

I'm trying to create a VBA script or a formula/function that converts a Julian Date (5001 or 15001) to a regular date (01/01/2015). I was able to find the following formula that converts a 5 character Julian Date to Gregorian Date and it works fine. I'm no mathematician so I'm not sure how to write the formula for the 4 character JD and I have no idea where to even start for the reverse (Regular Date to JD). Any help on this matter would be greatly appreciated.
The formula for the 5 character JD is here:
Assuming that the Julian Date is in A1:
=DATE(IF(0+(LEFT(A1,2))<30,2000,1900)+LEFT(A1,2),1,RIGHT(A1,3))
Thanks in advance for any help.
You need to test the length of the target cell to determine whether or not it is 4 or 5 characters long (line break for clarity):
=DATE(IF(0+(VALUE(IF(LEN(A1)=5,LEFT(A1,2),LEFT(A1,1))))<30,2000,1900)
+VALUE(IF(LEN(A1)=5,LEFT(A1,2),LEFT(A1,1))),1,RIGHT(A1,3))
The reverse is much easier - just build a number out of the date parts and cast the resulting string to a number to get rid of any leading zero:
=VALUE(RIGHT(YEAR(A1),2)&TEXT(A1-DATE(YEAR(A1),1,0),"000"))
EDIT: Per comments, the following method will use the present decade if the first digit of a 4 year Julian date is less than or equal to the last digit of the current year, otherwise use 200x:
=DATE(IF(0+(VALUE(IF(LEN(A1)=5,LEFT(A1,2),LEFT(A1,1))))<30,
IF(LEN(A1)=5,2000,IF(LEFT(A1,1)<=RIGHT(YEAR(NOW()),1),2010, 2000)),1900)
+VALUE(IF(LEN(A1)=5,LEFT(A1,2),LEFT(A1,1))),1,RIGHT(A1,3))
Almost forgot... If you need the formula to remain valid after 2019 you can replace the 2010 with 2000+(MID(YEAR(NOW()),3,1)*10).
You can use this formula from this page:
=DATE(IF(0+(LEFT(JULIAN_DATE_CELL,2))<30,2000,1900)+LEFT(JULIAN_DATE_CELL,2),1,RIGHT(JULIAN_DATE_CELL,3))
You need to replace JULIAN_DATE_CELL with the cell number that you stored the Julian date.
Do you need to accommodate dates before 2000? If not then you can use this formula:
=DATE(IF(LEN(A1)=5,LEFT(A1,2)+100,LOOKUP(YEAR(NOW()),FLOOR(YEAR(NOW()),10)+LEFT(A1)-{10,0})),1,RIGHT(A1,3))
That uses LOOKUP function to lookup the current year against the possible options, e.g. currently if you have 6001 in A1 that looks up 2015 against an array like {2006,2016} and the lower value is chosen. If you do the same calculation next year 2016 will be chosen.
This formula will work in to the future, e.g. in 2020 it will interpret 9001 as 1st Jan 2019.
For reversing the calculation do you always want a 4 digit JD, what about 2010 or 2020?

Resources