I want to covert a column with Excel date numbers (float) to datetime, below is the function I am trying to use:
import datetime
datetime.datetime.fromtimestamp(42029.0).strftime('%Y-%m-%d')
Bu the result I got is: '1970-01-01',I don't think it is right, I must missing a constant which should be added to the variable, because in the excel the number 42029.0 represents date: 1/25/2015.
Can anyone please advise how to improve the code?
datetime.fromtimestamp() follows the unix convention and expects seconds since '1970-01-01'. The Excel date number for '1970-01-01' is 25569, so you have to subtract this number from your given date number and multiply the result, which is in days, with 86400 (seconds per day):
datetime.datetime.fromtimestamp(
(42029.0 - 25569) * 86400).strftime('%Y-%m-%d')
'2015-01-25'
I have a date that looks like this text. 17-OCT-16 03.24.11.000000000 AM
I need to format that text into a date that I can then manipulate. Ultimate I want to transform that time to millis from epoch but I'm not sure if that's even possible
Its definitely possible, you can make use of DATEVALUE and TIMEVALUE function which convert a time or date in string format to date/time format:
=DATEVALUE(LEFT(A1,9)) + TIMEVALUE(SUBSTITUTE(MID(A1,11,8), ".", ":")&MID(A1, 19, 9))
This will give you a single number (42660.1417939815) in this case which is the number of days since 1/1/1900 (including milliseconds)
It should just be some simple maths to get total milliseconds
I need a formula in excel to convert minutes to hours. Until now came the following formula:
=A1/1440
So, 180minutes its converted to 03:00, when formatted as hh:mm
But, i need also to convert long minutes, like 1600. In this case, the formula converts to 02:40, when it should show 26:40.
Any ideas?
You can try
=INT(A1/60)&":" &MOD(A1,60)
and =TEXT(FLOOR(A1/60,1),"00")&":"&TEXT(MOD(A1,60),"00") for Format hh:mm
Use exactly the same formula you are using now, but change the display format to:
[h]:mm:ss
That will display in the format you want AND allow you to perform operations on the values.
( With format showing in the top of the time columns)
[h]:mm:ss hh:mm:ss Equal?
=1600/1440 =1600/1440 =G23=F23
=F23+1600/1440 =G23+1600/1440 =G24=F24
Gives
[h]:mm:ss hh:mm:ss Equal?
26:40:00 2:40:00 TRUE
53:20:00 5:20:00 TRUE
I am looking to convert a text time with a and p on the end into usable time in excel I have used the mid function and I does not seem to recognize the a/p and makes all the times am unless its 12--. Then it will return a PM time. I have used the Mid function and have searched the threads.
Times in the database look like
10/ 1/14 5:14P
These are text
I have used the mid function
=TIMEVALUE(MID(B6,9,6))
Returning
5:14:00 AM
when the time should be a Pm or 17:14
Help would be appreciated
Thanks
Try this :
=SUBSTITUTE(SUBSTITUTE(A1,"A", " AM"),"P", " PM")+0
where A1 has the value.
Format the cell to the kind of date / time / datetime format that you want ; formatting it to :
dd-mm-yyyy h:mm:ss AM/PM
will display :
10-01-2014 5:14:00 PM
I am trying to convert string in following format: 20130817T140000Z(17th Aug 2013 at 14:00) to epoch time (seconds since 1970) in an MS Excel 2013.
Tried cell formatting, but it doesn't work with T and Z or the format in general.
This will convert your date into somethign Excel will understand, If you have your date in Cell A1, Then convert that into Epoch Time
=(DATE(LEFT(A1,4),MID(A1,5,2),MID(A1,7,2)) + TIME(MID(A1,10,2),MID(A1,12,2),MID(A1,14,2))-25569)*86400)
Try this:
A1=20130817T140000Z
A2=DATE(LEFT(A1,4),MID(A1,5,2),MID(A1,7,2))
A3=(DATEDIF("01/01/1970 00:00:00",A2,"D")+TIME(MID(A1,10,2),MID(A1,12,2),MID(A1,14,2)))*24*60*60
A1 is your input date as text, A2 is a formatted date, and A3 is a seconds difference between your date and epoch start date.
Useful link
Update: based on #user2140261 suggestions.
Assuming the string to convert is in cell B1 you can use the following with a custom format on the cell to get the date/time.
=DATE(MID(B1,1,4),MID(B1,5,2),MID(B1,7,2))+TIME(MID(B1,10,2),MID(B1,12,2),MID(B1,14,2))
The custom format is:
dd/mm/yyyy hh:mm:ss
This will get you the date with accuracy to the minute. You can follow the pattern to get seconds if necessary.
=DATE(VALUE(LEFT(A1,4)),VALUE(RIGHT(LEFT(A1,6),2)),VALUE(RIGHT(LEFT(A1,8),2)))+VALUE(RIGHT(LEFT(A1,11),2))/24+VALUE(RIGHT(LEFT(A1,13),2))/(24*60)
You could use this version to convert your string to Epoch time
=(TEXT(LEFT(A1,8)&MID(A1,10,6),"0000-00-00 00\:00\:00")-25569)*86400
This uses TEXT function to convert your string into a string that looks like a valid date/time - when you subtract 25569 (1/1/1970) that will co-erce that string to a valid date/time and the result can be multiplied by the number of seconds in a day to get Epoch time