How to convert a String date to a Date - excel

How can I convert this string:
Tue Jan 24 14:59:20 BRT 2017.
Into a date that includes day month year and time and timezone, using Excel functions only.
I have several cells with dates following this format. I have to compute the difference between some of these dates in minutes. I believe that the first step is converting the date to a String to a real date information. Then, I will be able to: order the dates and compute the time between consecutive dates.

Use this formula:
=--(SUBSTITUTE(MID(A1,5,LEN(A1)),"BRT",""))
Then format it to the format you want.
It will now work in math equations.

Related

Create list of custom non-standard date formats in excel

I have a table in excel with non-standard dates written in four general formats (first column), and would like to convert each to a standard excel date format (2nd column).
Early 2022 should convert to 01/14/2022
YE 2022 should convert to 12/01/2022
2Q 2022 should convert to 05/01/2022
2H 2023 should convert to 09/01/2023
Ideally, I would like to use the custom format table and just add these 4 rules but a formula addressing each of the 4 scenarios would also suffice.
Non-Standard Dates
Converted Dates
Early 2022
01/14/2022
YE 2022
12/01/2022
2Q 2022
05/01/2022
2H 2023
09/01/2023
Most likely, nested IF statements will be required that check for the words "Early", "YE", "2Q" and "2H" will be required, followed by amending of last 4 digits.
I've only figured out how to check for one word, but the IF statements need to be nested. =IF(A2="Early", "01/14/", "" ) works, but of course I need to replace the last portion ("") with a new IF statement to look for the next phrase ("YE") and so forth. I also need to amend the last 4 digits.
You could create a table like this
If that table is in I10:J13 and your estimated dates are in column A, this formula would return the date you want.
=DATE(MID(A1,FIND(" ",A1)+1,LEN(A1)),MONTH(VLOOKUP(LEFT(A1,FIND(" ",A1)-1),$I$10:$J$13,2,FALSE)),DAY(VLOOKUP(LEFT(A1,FIND(" ",A1)-1),$I$10:$J$13,2,FALSE)))
The DATE function takes three arguments: year, month, and day. The year is determined by finding a space and assuming everything after the space is the year. The month and day argument find the date in the lookup table and use MONTH() and DAY() to extract those portions. It doesn't matter what year your dates in the lookup table have because this uses the year from the estimated date.

How we can extract Day, Date, Time in Excel which is in the format of following Fri Aug 07, 2020 05:12 UTC?

Long Date
Fri Aug 07, 2020 05:12 UTC
Day | Date | Time |
Friday | 07:10:2020 | 05:12 |
to get the date from that string use:
=--MID(A1,5,LEN(A1)-8)
Put that in three cells. Then format the cells:
day cell: dddd
Date Cell: dd\:mm\:yyyy
Time Cell: HH:MM
You could use the following to put the text string into just a date time format that excel understands:
=DATEVALUE(RIGHT(LEFT(A1,LEN(A1)-4),LEN(A1)-8))
The above will not be affected by number of digits for year, day or hour; only that the bit it is using has 4 chars at the front (Fri and space) and 4 at the end (space and UTC).
Since you have two digits for both day and hour, this could be simplified with using MID, like:
=DATEVALUE(MID(A1,5,LEN(A1)-8))
To extract a date from a text string representing a date, you can use the DATE function e.g. =DATE([year],[month],[day]).
To get those parts from a text string you can use =MID([input text string], [start position], [number of characters]). So you could do MID for each component (year, month etc) needed, then put the results through the DATE function.
Date formats in Excel are distinguished between what is stored and what is displayed.
What is stored depends on your excel settings.
What is displayed depends on your excel settings as well as your "regional and language options" or equivalent settings in your computer's operating system.
To change what is displayed, set a custom format (ctrl-1, first tab, last list item) to something like Ddd Mmm dd, yyyy hh:mm.
Otherwise regional and language options, and program settings, can override how the date is shown (which can be important if you are sharing workbooks, especially with unknown future users).
Is the input UTC or do you need to convert?
If you need to convert, do you have a fixed offset in hours? If so, it is a simple formula. For example: =A1+3/24 for UTC-3 hours.
To change what is stored, first understand whether the number stored represents the number of days since 1 Jan 1901, or 1 Jan 1904, or some other convention (such as 1 Jan 1970).
Then decide if you want to store it as a date or a text string.
Then decide if you want to store it as 3 copies of the same value (each displaying a different aspect: day, date, time) or if you just want each value to be its own part not the whole date "hidden" and the display set.
To store it as a text string, use =TEXT(A1,"Dddd"), =TEXT(A1,"MM:DD:YYYY") and =TEXT(A1,"HH:MM").
Watch out for 24 or 12 hour time: the difference is whether "AM/PM" is appended. Your input is likely 24h time but check another example from the dataset to be sure.

Unix timestamp from csv gives me the same date, although different values

I have a csv file with some columns, like date and time. The date is a 10 digit format, unix format from what i read online.
examples are: 1567285228,1567285348, 1567371053.I found that I can use the formula: =(((A2/60)/60)/24)+DATE(1970,1,1) to calculate the proper date from the code, but the problem is that my csv is for one entire month, the codes are different, but the proper date gives me only 2 values: 01 sept 2019 and 31 aug 2019.
How can I find the REAL dates, for the WHOLE month?
Also, the time when the measurements are taken are for example: 712980, 713040
,713100,713160, but when i use excel to format the time stamp to proper time, it only shows me 12 AM. How can I calculate the proper dates and time, so that I can analyse the data from the csv?

Converting text to date format YYQQ

I am storing project start and finish dates in the text format YYQQ. My goal is to convert this text to an actual date format, as to be able to substract finish and start dates to obtain the duration of a project in number of quarters.
For example if a project started in the third quarter of 2015, 15Q3 and finished in the second quarter of 2016, 16Q2, then it took 3 quarters to complete the project.
The excel function DATE requires text to be converted to the format YYMMDD, which is not what I want. Does excel have a function to convert for example text 16Q2 to date YYQQ format?
Excel does not have that function. But you can easily write a formula to do that conversion:
To convert to a normal excel date:
=DATE(LEFT(Start,2)+2000,(RIGHT(Start,1)-1)*3,1)
will return the starting date of the quarter.
For a date close to the middle of the quarter, something like:
=DATE(LEFT(Start,2)+2000,(RIGHT(Start,1)-1)*3,45)

How to recreate excel's Long type to Date type conversion in scala

I did a paste special of date column as values in excel. I want to convert the resulted long values back to dates in spark (using scala api).
Example: converting 41088.96389 to date in excel results in 6/29/16 23:08
same when did through cast(DataTypes.TimestampType) in spark, it gives 01 Jan 1970 11:24:48 GMT
Any links to how excel handles long type when converting to date will be appreciated.
Excel's number is the amount of days elapsed since 1st of January, 1900.
DateTime or Date usually accepts a UNIX epoch timestamp, which is the number of milliseconds (or sometimes seconds, depends on the implementation) elapsed since the 1st of January, 1970.
Converting between the two is not so easy, since you have to count for leap years, and maybe even time zones.
You can find multiple implementations for this in different languages, maybe you can port one of those:
https://gist.github.com/peter216/6361201
https://gist.github.com/christopherscott/2782634
Or maybe just try to normalize the Excel output if you have access to the sheet:
https://stackoverflow.com/a/11140924/1395437

Resources