I searched for a replacement of date -d in Nushell but I didn't find anything.
How can I get the current datetime minus N minutes ? Like this $((date now) - 30 minutes)
How can I get the current timestamp minus 30 minutes in nushell?
149 Views Asked by Howins At
1
You can subtract a duration (like
30min) from the current date provided bydate now(you can also add a negative duration with the same effect):So, if your input is an integer representing the amount of minutes, just append
"min"to it as a string, then useinto durationto convert it before subtracting/adding like above:For the sake of completeness, although not recommended, you could also go down the full arithmetic route by formatting the current date as UNIX timestamp measured in seconds using
format date "%s", then subtracting/adding the amount of minutes also converted into seconds (i.e. multiplied by sixty), and converting that further into nanoseconds (i.e multiplying again by 1 billion) because that's whatinto datetimeaccepts as numerical input. Use it with the--timezone LOCAL(or-z l) option to re-include your local time zone (which got lost with the UNIX timestamp).For super precision, you could even extract the UNIX timestamp directly in nanoseconds using
%s%fas the format string, then subtract/add the amount of minutes also converted into nanoseconds: