I am trying to build a custom date format that matches the format below. I've included an example of the number value (date) and how the output should look. I've tried something like: ddd mmm d, yyyy h:mm:ssAM/PM [ddd mmm d, yyyy h:mm:ssAM/PM] as a custom format, but can't seem to get it to work. Can you tell me where I am going wrong? Thank you in advance!
(Date time) 1546926706 = (Formatted Output) Mon Jan 7, 2019 9:51:46pm PST [Mon Jan 7, 2019 10:51:46pm]
Attempt at translating format into custom format Excel understands:
`
ddd mmm d, yyyy h:mm:ssAM/PM [ddd mmm d, yyyy h:mm:ssAM/PM]
Basically I'm trying to reverse engineer a custom date format because I can't access the system that is sending me the data and need it to make sense on for users on the front end.
`
1546926706 is UNIX/POSIX time where each 1 is a second after at 1-Jan-1970. You need a conversion to an excel datetime where each 1 is a day that starts 1-Jan-1900.
'Tue Jan 8, 2019 5:51:46 AM PST
=TEXT(1546926706/86400 + 25569, "ddd mmm d, yyyy h:mm:ss am/pm \P\S\T")
That's returns text, not a true datetime but it shows you the conversion and format mask.
Related
I've autogenerated time from an API in the format "15-03-2022 01:10", here I would like to take the timepart and convert it to 13:10 and so on. As there is no AM/PM at the end of time, it is getting difficult to apply the Excel time format, is there any way I can achieve this using excel VBA.
I Searched everywhere, but couldn't find the correct solution for the above issue. Some example like
11:30 --> 11:30 Morning
11:30 --> 23:30 Night
just trying to figure out how to distinguish between the above 2 formats in a single day. But the end output needs to be in 24hr format.
Always handle date and time as Date, not text, no exceptions. So:
NewTime = DateAdd("h", 12, CDate("15-03-2022 01:10"))
Then apply the format you wish for display, here:
dd-mm-yyyy hh:nn
Every day in Excel is 1, so half a day is 0.5.
CDate("15-03-2022 01:10") + 0.5 to add half a day.
Also you can concatenate PM to the end of the string
CDate("15-03-2022 01:10 PM")
Then you can output any display text you want with the Format function.
Format(MyTime, "MMM dd, hh:mm:ss am/pm") would display "Mar 15, 01:10:00 PM"
For 24 Hour time formatting, remove the am/pm:
Format(MyTime, "MMM dd, hh:mm:ss") would display "Mar 15, 13:10:00"
I'm using RSS feeds from multiple sources and I'm sorting the feeds by date. However, the dates I receive are in different time zones.
This is the format of some of the date strings that I get:
Wed 08 Dec 2021 01:40:31 -0500
Wed 08 Dec 2021 11:11:19 -0600
The "-500' indicates the time zone which is UTC-5. I need to use that "-0500" to convert this string into a date and the date needs to be only in UTC.
Basically from "Wed 08 Dec 2021 01:40:31 -0500" to "12/08/2021 06:40:31"
I've managed to split the string up to sort by date but because of the time difference, it doesn't really help.
Is there coding which I can use to convert the string as-is into date and only UTC time? Or is there just a place where I can start?
Thank you in advance.
Using DateTime.ParseExact, you specify a format to convert from, and that can include "zzz" for the timezone offset. You can also specify that you want the result in UTC:
Dim s = "Wed 08 Dec 2021 01:40:31 -0500"
Dim d = DateTime.ParseExact(s, "ddd dd MMM yyyy HH:mm:ss zzz", Nothing, Globalization.DateTimeStyles.AdjustToUniversal)
Console.WriteLine(d.ToString("yyyy-MM-dd HH:mm:ss"))
Console.WriteLine(d.Kind.ToString())
Outputs:
2021-12-08 06:40:31
Utc
Of course, format the result as you desire.
Alternatively, if you need to, you can keep the offset by using a DateTimeOffset structure and adjust it to UTC for representation as a string:
Dim s = "Wed 08 Dec 2021 01:40:31 -0500"
Dim d = DateTimeOffset.ParseExact(s, "ddd dd MMM yyyy HH:mm:ss zzz", Nothing)
Console.WriteLine(d.ToUniversalTime.ToString("yyyy-MM-dd HH:mm:ss"))
Outputs:
2021-12-08 06:40:31
Date
19112018
19112016
19112015
19112013
I have a column named Date.
I want to convert 19112018 to 2019-11-20 18:00
19 means year 2019
11 month
20 days
18 is hour
Thanks .
Use the following formula:
=DATE(20&LEFT(A2,2),MID(A2,3,2),MID(A2,5,2))+RIGHT(A2,2)/24
Or:
=--(20&REPLACE(REPLACE(REPLACE(A2,7,0," "),5,0,"-"),3,0,"-")&":00")
Then format the output cell:
yyyy-mm-dd hh:mm
I have a text formatted date that looks like this:
June 12th 2017, 9:07am PDT
How can I transform it in a date format (the classic methods Format Cells and DateValue() don't work)?
Thank you.
My solution uses a helper table listing all the 12 months and their serial number at A1:B12
January 1
February 2
March 3
April 4
May 5
June 6
July 7
August 8
September 9
October 10
November 11
December 12
Assuming the value is in D10
Getting the separate elements
Month:
=VLOOKUP(LEFT(D10,FIND(" ",D10)-1),A1:B12,2,FALSE)
Date:
=IFERROR(VALUE(RIGHT(LEFT(D10,FIND(" ",D10)+2),2)),RIGHT(LEFT(D10,FIND(" ",D10)+1),1))
Year:
=RIGHT(LEFT(D10,FIND(",",D10)-1),4)
Hour:
=IF(RIGHT(LEFT(D10,FIND(":",D10)+4),2)="am",RIGHT(LEFT(D10,FIND(":",D10)-1),2),RIGHT(LEFT(D10,FIND(":",D10)-1),2)+12)
Minute:
=RIGHT(LEFT(D10,FIND(":",D10)+2),2)
All this combined in the DATE and TIME function to give a single formula:
=DATE(RIGHT(LEFT(D10,FIND(",",D10)-1),4),VLOOKUP(LEFT(D10,FIND(" ",D10)-1),A1:B12,2,FALSE),IFERROR(VALUE(RIGHT(LEFT(D10,FIND(" ",D10)+2),2)),RIGHT(LEFT(D10,FIND(" ",D10)+1),1)))+TIME(IF(RIGHT(LEFT(D10,FIND(":",D10)+4),2)="am",RIGHT(LEFT(D10,FIND(":",D10)-1),2),RIGHT(LEFT(D10,FIND(":",D10)-1),2)+12),RIGHT(LEFT(D10,FIND(":",D10)+2),2),0)
Then change the format of the cell to:
mmmm dd yyyy hh:mm AM/PM "PDT"
This will give:
June 12 2017 09:07 AM PDT
To add a comma(,), use the custom format:
mmmm dd yyyy"," hh:mm AM/PM "PDT"
I am trying to convert seconds to dd hh:mm:ss format
I am using the formula:
=A1/(24*60*60)
For 1099014 I get the result 12 17:16:54
For 2198028 I get the result 25 10:33:48
But for 3297042 I get the result 07 03:50:42
And the value for which I need the result is 7473837 and I get the result 26 12:03:57 which I suppose is not correct.
So why does the value fluctuates like this in excel and how can I exactly calculate the correct value?
Thank You
3,297,042 seconds represents 38 days 03:50:42
If you extend you format to have the whole date: yyyy MM dd hh:mm:ss
You'll see: 1900 02 07 03:50:42
That's why your format string gives you 07 03:50:42
Same thing for 7,473,837 where date is 1900 03 26 12:03:57
I might be wrong, but it seems there's no format (like [h] for hours) to tell excel to diplay number of days. Instead you could use:
=INT(A1/86400) & TEXT(A1/86400," hh:mm:ss")