How to convert this date format - time

I have wierd date format:
ID, Time, Value 1 [mg/l]
9867, 43788.5946644, 5.266029
9851, 43788.5529745, 5.526279
9835, 43788.5113079, 6.008881
and I would like to convert it, but I can not even recognize this one. an anyone help me? It might be conversion to timestamp, simple date or anything else that is readable.
I know the outputs:
43788.5946644 - 19/11/2019 14:16
43788.5529745 - 19/11/2019 13:16
43788.5113079 - 19/11/2019 12:16

By accident I found an answer, this is a excell date. https://www.excel-exercise.com/date-format-in-excel/
can be converted using powershell command:
[DateTime]::FromOADate(43788.5946528) -> Tuesday, November 19 2019 14:16:18

Related

How to convert unix timestamp to formatted date in ruby?

I'm struggling with ruby date api. I need to convert a timestamp number to formatted date. But when i use:
Time.at(1517486994710).to_datetime
or
DateTime.strptime("1517486994710",'%s')
(1517486994710 is unix timestamp for today), i see 50057 year as output. What i'm doing wrong?
You have the epoch with milliseconds. Use %Q formatter:
DateTime.strptime("1517486994710",'%Q')
#⇒ Thu, 01 Feb 2018 12:09:54 +0000
Your script is correct but your epoch is incorrect. Today epoch is 1517491785.
You probably got the js epoch which counts in milliseconds
DateTime.strptime("1517486994",'%s') # removed 710

Parse line for specific date format?

Writing a script using bash. I am trying to look through lines in a file for a specific date format:
date +"%a %b %d %T %Z %Y"
For example, if the line were
/foo/bar/foobar this 12 is 411 arbitrary stuff in the line Wed Jun 10 10:10:10 PST 2017
I would want to obtain Wed Jun 10 10:10:10 PST 2017.
Any way to search for specific date formats?
I'm not sure whether you'll agree with this approach. But if this is for some quick, non-recurring work, I won't look for a perfect solution that can handle all the scenarios.
To start with, you can use the following too generic pattern to match the part you want.
cat file | sed -n 's/.*\(... ... .. ..:..:.. ... ....\).*/\1/p'
Then you can enhance this further restricting the matches as you need.
E.g.
cat file | sed -n 's/.*\([a-Z]\{3\} [a-Z]\{3\} [0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9] [A-Z]\{3\} [0-9]\{4\}\).*/\1/p'
Note that this still is not perfect and can match invalid contents. If you find it still not good enough, you can further fine tune the pattern to the point you want.

Ruby unix date incorrect

I have the following Unix timestamp: 1478698378000
And I'm trying to show this as a datetime in Ruby, e.g.
<%= Time.at(#timestamp).to_datetime %>
Which should be returning a date of: Wed, 09 Nov 2016 13:32:58 GMT but the above code actually returns a date of: 48828-02-01T13:26:40+00:00 Ignore formatting!
As you can see it thinks that timestamp is 2nd Feb 48828 13:26:40.
Why is the datetime coming out completely incorrect and the year so far into the future like that? Checking the timestamp on http://www.epochconverter.com/ reveals the timestamp to be correct, so it's Ruby that's returning it incorrectly.
Time.at expects seconds as an argument and your timestamp is an amount of milliseconds. See documentation on Time.at
Why won’t you check the unix timestamp correctness against “Fashion Week Magazine” or “Cosmopolitan” Site?
Unix timestamp is an amount of seconds lasted since 1970-01-01 UTC:
date --date='#1478698378000'
mar feb 1 14:26:40 CET 48828
BTW, dropping last three zeroes gives you back what you’ve expected:
date --date='#1478698378'
mié nov 9 14:32:58 CET 2016

Subtract 20 month from user provided date in yymm in unix

oldest_year_month_temp=201602
NUM_PART_RETAIN=20
oldest_year_month=`date --date="$(oldest_year_month_temp +%Y%m) - $NUM_PART_RETAIN month" "+%Y%m"`
Date is not coming as expected.
One easy way to do it would be to simply append a 01 to your input of yymm to provide a format date -d could read as the starting date, then simply subtract 20 months and output the resulting date in %y%m format. For example, if you provide the date 9910 (Oct. 1999), you can do:
$ date -d "991001 - 20 months" +%y%m
9802
Which returns Feb. 1998 (20 months earlier)
(note: the $ above just indicates a command by a normal user as opposed to # indicating a command by the super user (e.g. root))
Inside the $(...) there must be a command, e.g. $(date ...).
This should have been obvious from the error message you got, which was probably oldest_year_month_temp: no such command.
When reading from a variable, you must write a $ before its name.

Calculate 15 minutes ago in shell

I have a time-stamp like 7:00:00, which means 7am.
I would like to write a short command that returns 06:45:00, or simply 06:45, preferably using date command so that I can avoid long shell script. Do you have any elegant solution?
I'm also looking for a 24h format. For example, 12:00:00 - 15 minutes = 11:45:00.
With GNU date, use 7:00:00 AM - 15 minutes as d (--date) string :
% date -d '7:00:00 AM - 15 minutes' '+%H:%M'
06:45
+%H:%M sets the output format as HH:MM.
On BSD variants Date has a -v flag which can be used to take the current timestamp and display the result of a positive or negative adjustment.
This will subtract 15mins from the current timestamp:
date -v -15M

Resources