Converting Dates - What format is 20130606T083000.093660900? [duplicate] - linux

This question already has an answer here:
How to convert string format date yyyymmddThhmmss.sss to date in Bash?
(1 answer)
Closed 6 months ago.
Bit of an issue with date formatting:
Looking to format this date format " 20130606T083000.093660900 "
2013 06 06 T 08 30 00. 093660900
YYYY MM DD T HH MM SS NANOSECS
Formatting this into Epoch (which I believe is the second time given below without decimals) time would be great, I don't have much experience working with date time and changing them.
My goal is to realistically subtract
20130606T083000.093660900 FROM 1370507400093660900
Any help with even telling me what format the first date is, as it is apparently NOT ISO 8601, thanks!

You can use sed to convert the input to something GNU date can parse, then use GNU date to convert it to the format of the other date. Then compare:
din='20130606T083000.093660900'
dcmp='1370507400093660900'
dstr=$(sed 's/\(..\)\(..\)T\(..\)\(..\)/-\1-\2T\3:\4:/' <<<"$din")
timestamp=$(TZ=UTC0 date +%s%N --date="$dstr")
diff=$(( dcmp - timestamp ))
# diff is now: 0
I have forced timezone to avoid localisation concerns.

Related

How to convert minutes into (YY MM DD HH:mm:ss) in excel?

I'm using manipulating time in excel.
I have the date in minutes I want to convert it into the format.
YY MM DD HH mm
where:
mm:Minutes
HH:Hours
DD:Days
MM:month
YY: year
Im using the following logic:
For 124 minutes I have
124/60= 2 hours
124%60 = 4 minutes
and so on for the days and the months and the years
The units Im using are:
mm-> HH /24
HH-> MM /30
MM-> YY /12
But something is really wrong:
Does anyone have an idea what was happening?
Thanks a lot, guys
Your calculations are "really wrong" because in real life, months have anywhere between 28 and 31 days, so you cannot represent a large number of minutes as a "date" that uses variable measures for years and months.
On the assumption that as units of measure you want to use ...
Year = 360 days
month - 30 days
... you can calculate as follows:
That's also what your calculation shows. If something is "really wrong" with that, it's probably your expectation, which is based on the traditional 365.25 day year.
Maybe you want to edit your question and explain what you expect as the "really correct" result.
In Excel dates are fractional number of days from 31-Dec-1899 (date 0 is formatted as 0/1/1900). So why don't you just add your minutes (after dividing by (24*60) to convert to days) to the earliest valid date in EXCEL (1900-01-01) and use the TEXT function to format:
=DATEVALUE("1900-01-01")+(21/24/60)-1
The bold part is your minutes.
This is now a proper EXCEL date; you can use TEXT function to format it into any way you like, or you can use DAY(), HOUR(), etc. functions to extract parts.
Having said that I don't know what your minutes represent; What date does Full Time in Minutes:21 correspond to?

How to convert a bash string to date format? [duplicate]

This question already has answers here:
How to convert YYYYMMDDHHMMSS to a date readable by `date`
(6 answers)
Closed 10 months ago.
I have a bash string 20220416124334 (the string is not epoch) and I want to convert it to date format so it should look like this: 2022/04/16 12:43:34
I've tried:
[manjaro#manjaro ~]$ date -d '20220416124334' "+%Y/%m/%d %H:%M:%S"
date: invalid date ‘20220416124334’
How should I do it correctly ?
I would expect to use the date command, as you employ it, with a number that represents the number of seconds since the epoch. It seems your number is a formatted date yyyymmddhhmiss.
If you don't need to validate the string that represents a formatted date, then you can use sed to insert extra formatting characters:
echo '20220416124334' | sed -E 's/(....)(..)(..)(..)(..)(..)/\1\/\2\/\3 \4:\5:\6/'
If you end up taking as input a number of seconds since the epoch, then do it this way, keeping in mind that a number means different times in different time zones at different times of the year (eyeroll):
date -u -r 1650113014 "+%Y/%m/%d %H:%M:%S"

Convert timestamp to DateTime in excel

Is there any way in Excel to convert the timestamp in the format
{"_seconds":1570448585,"_nanoseconds":834000000}
to readable format (Human-friendly)?
1-Oct-2018 12:00 PM
The seconds look like a UNIX timestamp.
UNIX time started counting seconds 1970.
To convert it you need to start with the date 1970-01-01 and add the days as a float.
=DATE(1970,1,1) + A1/60/60/24
I found the solution - There is a feature called "Text to column"

How to convert a String date to a Date

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.

Convert fraction of day to POSIX times in R [duplicate]

This question already has answers here:
Convert decimal day to HH:MM
(3 answers)
Closed 3 years ago.
I have a dataset that encodes a date-time into two separate variables. Normally, I'd just paste them together inside of an as.POSIXct and carry on. However, the date is provided as a string, and the time of day as a fraction of 24 hours - e.g., 12pm is 0.5, 9:30am is 0.1458333, etc.
It doesn't seem all that tricky to convert the fractional days into clock hours, but I'd prefer to use a pre-existing function if possible. Does something like that exist in base R? A package?
If it's any use, this is an Excel (xlsx) time field imported into R through RODBC.
EDIT
Oddly enough, upon revisiting this problem, the times are now read in as POSIXct. Not sure what to make of that.
The R News 4/1 Help Desk article has a section on reading Excel dates in R.
POSIXct values are simply the number of seconds since midnight GMT 1970-01-01. (So you need to pay attention to your offset from UTC.) You can use the date part and add the number of days times 24*3600 (as.Date(dtval) to your time value * 24*3600. Gabor pointed to the article in R News (which he wrote, thank you, Gabor.)
You didn't give an example of the string. If you are getting your date as a string, then as.Date(strDate) will convert a variable "strDate" to Date class when it is in either "YYYY-MM-DD" or "YYYY/MM/DD" format. Otherwise the formatting codes are on the ?strptime page.
Once you have a POSIXct-classed variable you can just add the number of seconds. This example add 30 minutes to midnight today Feb 1, 2011 (in my time zone which is UTC-5):
> as.POSIXct(as.Date("2011-02-01")) +30*60
[1] "2011-01-31 19:30:00 EST"
And this is your time value added to midnight my time:
> as.POSIXct(as.Date("2011-02-01 00:00", tzone="UTC"))+3600*5 + 3600*24*timeval
[1] "2011-02-01 03:29:59 EST"

Resources