Converting unix time into date-time via excel - excel

Trying to convert 1504865618099.00 Unix time into a readable date time.
I tried this:
=(UNIX + ("1/1/1970"-"1/1/1900"+1)*86400) / 86400
But it's not working.

To convert the epoch(Unix-Time) to regular time like for the below timestamp
Ex: 1517577336206
First convert the value with the following function like below
=LEFT(A1,10) & "." & RIGHT(A1,3)
The output will be like below
Ex: 1517577336.206
Now Add the formula like below
=(((B1/60)/60)/24)+DATE(1970,1,1)
Now format the cell like below or required format(Custom format)
m/d/yyyy h:mm:ss.000
Now example time comes like
2/2/2018 13:15:36.206
The three zeros are for milliseconds

=A1/(24*60*60) + DATE(1970;1;1) should work with seconds.
=(A1/86400/1000)+25569 if your time is in milliseconds, so dividing by 1000 gives use the correct date
Don't forget to set the type to Date on your output cell. I tried it with this date: 1504865618099 which is equal to 8-09-17 10:13.

TLDR
=(A1/86400)+25569
...and the format of the cell should be date.
If it doesn't work for you
If you get a number you forgot to format the output cell as a date.
If you get ##### you probably don't have a real Unix time. Check your
timestamps in https://www.epochconverter.com/. Try to divide your input by 10, 100, 1000 or 10000**
You work with timestamps outside Excel's (very extended) limits.
You didn't replace A1 with the cell containing the timestamp ;-p
Explanation
Unix system represent a point in time as a number. Specifically the number of seconds* since a zero-time called the Unix epoch which is 1/1/1970 00:00 UTC/GMT. This number of seconds is called "Unix timestamp" or "Unix time" or "POSIX time" or just "timestamp" and sometimes (confusingly) "Unix epoch".
In the case of Excel they chose a different zero-time and step (because who wouldn't like variety in technical details?). So Excel counts days since 24 hours before 1/1/1900 UTC/GMT. So 25569 corresponds to 1/1/1970 00:00 UTC/GMT and 25570 to 2/1/1970 00:00.
Now if you also note that we have 86400 seconds per day (24 hours x60 minutes x60 seconds) and you will understand what this formula does: A1/86400 converts seconds to days and +25569 adjusts for the offset between what is zero-time for Unix and what is zero-time for Excel.
By the way DATE(1970,1,1) will helpfully return 25569 for you in case you forget all this so a more "self-documenting" way to write our formula is:
=A1/(24*60*60) + DATE(1970,1,1)
P.S.: All these were already present in other answers and comments just not laid out as I like them and I don't feel it's OK to edit the hell out of another answer.
*: that's almost correct because you should not count leap seconds
**: E.g. in the case of this question the number was milliseconds since the the Unix epoch.

If you have ########, it can help you:
=((A1/1000+1*3600)/86400+25569)
+1*3600 is GTM+1

in case the above does not work for you. for me this did not for some reasons;
the UNIX numbers i am working on are from the Mozilla place.sqlite dates.
to make it work : i splitted the UNIX cells into two cells : one of the first 10 numbers (the date) and the other 4 numbers left (the seconds i believe)
Then i used this formula, =(A1/86400)+25569 where A1 contains the cell with the first 10 number; and it worked

You are seeing the date as ######## most likely because by definition the EPOCH times is in seconds - https://en.wikipedia.org/wiki/Unix_time. This means the number should be 10 characters long. Your number has 13 characters (see 1504865618099) and it is most likely in milliseconds (MS). In order to fix the formula just divide the number by 1000. Just keep in mind this way you'll loose the MS precision, but in most cases this is OK. So the final formula should be:
=A1/(86400 * 1000) + DATE(1970,1,1)

Just point and shoot.
Replace the C2 with your cell no. No need to format your Excel cell.
Also, you can use this unixtimestamp website to verify your data.
International format (ISO 8601):
=TEXT(C2/(1000*60*60*24)+25569,"YYYY-MM-DD HH:MM:SS")
2022-10-20 00:04:22
2022-10-20 00:05:20
2022-10-20 00:14:58
US format:
=TEXT(C2/(1000*60*60*24)+25569,"MM/DD/YYYY HH:MM:SS")
10/20/2022 00:04:22
10/20/2022 00:05:20
10/20/2022 00:14:58
Europe format:
=TEXT(C2/(1000*60*60*24)+25569,"DD.MM.YYYY HH:MM:SS")
20.10.2022 00:04:22
20.10.2022 00:05:20
20.10.2022 00:14:58
If you only need the date, remove the 'HH:MM:SS'.
=TEXT(C2/(1000*60*60*24)+25569,"YYYY-MM-DD")

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)

Excel formula for calculating Unix time stamp

I need a formula that will convert a date and time into a unix timestamp. I suppose a logical starting point could be in the format of the result of =NOW() i.e. 25/10/2021 15:26 or the result thereof split into two cells for convenience but I'm not quite sure about how to proceed.
Thanks in advance!
Since the Unix time stamp is the number of seconds since 1/1/1970, we can simple take the date we want, subtract 1/1/1970 and multiply by the number of seconds in a day:
=(NOW()-"1/1/1970")*60*60*24

How to calculate the number of seconds between two ISO 8601 datetime in Excel?

I have 2 datetime strings in ISO 8601 format e.g. 1900-01-01 00:00:00+00:00 and 2020-03-27 23:59:59+11:00.
How can I calculate the number of seconds between these 2 datetime strings using only Excel or Excel VBA?
All the answers I come across calculates the date part only, eventhough the questions asked for timestamp.
Function TOUNIX(dt) As Long
TOUNIX = DateDiff("s", "1/1/1970", dt)
End Function
Broken down for understanding/educational purposes:
LEFT(A1,FIND("+",A1)-1)-1 - extracts the date
(VALUE(LEFT(A1,FIND("+",A1)-1)-1) - converts date to a number (-1 to account for the first second being 0)
(LEFT(MID(A1,FIND("+",A1)+1,5),2) - extract the hour from the timezone
RIGHT(MID(A1,FIND("+",A1)+1,5),2) - extracts the minutes from the timezone
/60 - 60 minutes in an hour
/24 - 24 hours in a day
IF(LEFT(RIGHT(A1,6),1)="-",1,-1) - extract the timezone modifier to determine whether the timezone adds or subtracts from value
Combined to this point, we have the number converted value of the date
* 86400 - The amount of seconds in a day
=(VALUE(LEFT(A1,FIND("+",A1)-1)-1)+((LEFT(MID(A1,FIND("+",A1)+1,5),2)+(RIGHT(MID(A1,FIND("+",A1)+1,5),2)/60))/24)*IF(LEFT(RIGHT(A1,6),1)="-",1,-1))*86400
Where you are starting with 0, you won't need to subtract from another date. If you wanted to anyway, just duplicate the formula as needed.
you will want to look at the following functions.
For text manipulations:
LEFT
RIGHT
MID
FIND
SEARCH
Concatenate or &
For date manipulation:
Datevalue
Date
Year
Month
Day
For time manipulation:
Timevalue
Time
Hour
Minute
Second
You have a couple of options. You can either strip out each individual value and place it in the appropriate date/time individual function or rearrange the date and time as a string that is identifiable by the time/date value functions.
A little background on date and time in Excel. Date are stored as an integer. 1 represented 1900/1/1, 2 represents 1900/1/2 and so on. time is stored as a decimal representing fraction of a day. 00:00 is midnight and stores as zero , 12:00 noon is stored as 0.5 to represent half the day. 24:00 is not an official Excel time, though some function will work with it. To test if a date/time is stored as text or as an excel number, you can test the value of the cell with something like ISTEXT(A1), change the formatting to general and see if the display of the cell info changes, and least reliable is to look at the justification of the information in a cell which is left aligned by default for text and right aligned by default for numbers.
Lets assume your strings are stored in A1 and A2
Because Datevalue can be a little finicky and depends a bit on system settings to determine mm vs dd I go with the method of stripping the individual components. In your case because everything has leading zeros the position of month, day, hour, minute and seconds can be hard coded instead of searching the string starting position of each based of key characters like -, :, +, and space.
Grab the year:
=LEFT(A1,4)
Grab the month:
=MID(A1,6,2)
Grab the Day:
=MID(A1,9,2)
Make the date by dropping the results into DATE as follows:
=DATE(LEFT(A1,4),MID(A1,6,2),MID(A1,9,2))
Grab the hour:
=MID(A1,12,2)
Grab the minutes:
=MID(A1,15,2)
Grab the seconds:
=MID(A1,18,2)
Make the time by dropping the results into TIME as follows:
=TIME(MID(A1,12,2),MID(A1,15,2),MID(A1,18,2))
To grab the timezone I will use TIMEVALUE to demonstrate the other method. This will convert the timezone time or decimal value instead of text like the operations above.
Grab the timezone:
=TIMEVALUE(RIGHT(A1,5)*IF(LEFT(RIGHT(A1,6))="-",-1,1)
Then you just need to combine the results together to get the whole thing in an excel date and time format:
=DATE(LEFT(A1,4),MID(A1,6,2),MID(A1,9,2))+TIME(MID(A1,12,2),MID(A1,15,2),MID(A1,18,2))-TIMEVALUE(RIGHT(A1,5))*IF(LEFT(RIGHT(A1,6))="-",-1,1)
Now that the string is converted to an excel date you need to take the difference in the cells noting that the result is days. Then you need to convert it to seconds by multiplying it by 24*60*60 = 86400.
So if you put the results in B1 and B2 then the formula for difference in seconds would be:
=(B2-B1)*24*60*60
In the example below its (F14-F12). Also note that the cells displaying time or date and time have had custom formating applied to them to dispaly 24 hour clock or date and time combined.

calculate time difference in milliseconds excel

How do i calculate time difference in milliseconds between two columns where value of time has milliseconds component ... i.e. 16:33:44:056. Please refer to column E and J in pic .. i want to calculate difference in milli seconds between J and E ...
I have tried using the following formula to alculate difference in milli seconds but its giving incorrect results. =((RIGHT(J1,3))-(RIGHT(E1,3)))
It appears your date/time is a text value.
A "real" time value would normally be seen as 16:11:52.052
But by replacing the last : with a ., excel will see it as a real time and ordinary math can be done.
Excel stores date/time as days and fractions of a day.
So a formula that should work:
=ROUND((SUBSTITUTE(J1,":",".",3)-SUBSTITUTE(E1,":",".",3))*86400000,0)
Format the result as General or as Number with no decimal places
Try
=(J1-E1)*1000*60*60*24
or more concisely
=(J1-E1)*86400000
Then format your formula column to general.
This assumes the data is actually stored as datetime and not a text value.
If you change the format of your time columns, and the column to show the difference, to
hh:mm:ss.000
You can simply use subtraction:
(You'll have to tweak the actual cells to have . before the milliseconds, just formatting won't do it)
If the part of that string corresponding to hours, minutes and seconds is always the same, and time in J is always bigger than time in E, you could do:
=VALUE(RIGHT(J1;3))-VALUE(RIGHT(E1;3))

AFRACT`s Error Message (#VALUE!) to JON49`s to How do I convert hh:mm:ss.000 to milliseconds in Excel?

Apologies for opening a thread instead of posting comment on the Return-of-the-Archons Thread but i am not allowed to post anything since i do not have 50 reputation. I have the very same problem as AFRACT in How do I convert hh:mm:ss.000 to milliseconds in Excel?
Like probably AFRACT my data is in timestamp: 00:00:00.000 and is generated by a device to measure physiological data (heartrate, EDA, Skin Temp) and i want it to change to total seconds.miliseconds. I tried what JON49 proposed but got the (#VALUE!) Error, and then with timevalue, i got the (NAME!) Error. I have Excel 2016 and I am in Middle Europe (Germany)
A date is simply 1 for every day past 31-Dec-1899. Time is a decimal portion of a day; e.g. today is 42,800 and today at noon is 42,800.5. A true second is 0.0000115740740740741
If you want the seconds as integers with the milliseconds as decimal portion of 1 then multiply your true time value by 86,400 (i.e. 60*60*24) and format the cell as a number with three decimal places; e.g. 0.000.
If you want the time as a true time value then simply use a custom number format of [s].000. In the above image, C1 holds =A1 and is formatted as [s].000.

Resources