ksh - subtract 5 minutes from current time
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I need to get the date and time of the command date
minus 5 mins.
date:
29 Aug 2018 21:56:01
result:
29 Aug 2018 21:51:02
I tried to search on the Internet/forums but most of it involved using the -d
option and what I have doesn't support the -d
option.
This one works on Bash but I need something that works on ksh.
$ printf "%(%d %h %Y %H:%M:%S)Tn" $(( $(printf "%(%s)T") - 5 * 60 ))
shell-script scripting ksh timestamps
add a comment |Â
up vote
3
down vote
favorite
I need to get the date and time of the command date
minus 5 mins.
date:
29 Aug 2018 21:56:01
result:
29 Aug 2018 21:51:02
I tried to search on the Internet/forums but most of it involved using the -d
option and what I have doesn't support the -d
option.
This one works on Bash but I need something that works on ksh.
$ printf "%(%d %h %Y %H:%M:%S)Tn" $(( $(printf "%(%s)T") - 5 * 60 ))
shell-script scripting ksh timestamps
What ksh version do you have?ksh --version
. And can you also use perl or python?
â chaos
Sep 3 at 5:34
ksh --version
is not working for me. I can use perl.
â WaldenSchmidt
Sep 3 at 5:43
chaos is indulging in a little GNU Think. (-: The PD Korn shell does not support--version
. Neither does the MirBSD Korn shell. The bigger clue as to whether one is using 93 Korn is the93
in the name of the command,ksh93
as it usually is, notksh
as chaos said (which is PD Korn on several operating systems, not 93 Korn).
â JdeBP
Sep 3 at 10:44
Why are you demonstrating a 4:59 difference when the title says 5 minutes?
â Jeff Schaller
Sep 3 at 11:47
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I need to get the date and time of the command date
minus 5 mins.
date:
29 Aug 2018 21:56:01
result:
29 Aug 2018 21:51:02
I tried to search on the Internet/forums but most of it involved using the -d
option and what I have doesn't support the -d
option.
This one works on Bash but I need something that works on ksh.
$ printf "%(%d %h %Y %H:%M:%S)Tn" $(( $(printf "%(%s)T") - 5 * 60 ))
shell-script scripting ksh timestamps
I need to get the date and time of the command date
minus 5 mins.
date:
29 Aug 2018 21:56:01
result:
29 Aug 2018 21:51:02
I tried to search on the Internet/forums but most of it involved using the -d
option and what I have doesn't support the -d
option.
This one works on Bash but I need something that works on ksh.
$ printf "%(%d %h %Y %H:%M:%S)Tn" $(( $(printf "%(%s)T") - 5 * 60 ))
shell-script scripting ksh timestamps
shell-script scripting ksh timestamps
edited Sep 3 at 6:06
slmâ¦
239k65494665
239k65494665
asked Sep 3 at 4:46
WaldenSchmidt
182
182
What ksh version do you have?ksh --version
. And can you also use perl or python?
â chaos
Sep 3 at 5:34
ksh --version
is not working for me. I can use perl.
â WaldenSchmidt
Sep 3 at 5:43
chaos is indulging in a little GNU Think. (-: The PD Korn shell does not support--version
. Neither does the MirBSD Korn shell. The bigger clue as to whether one is using 93 Korn is the93
in the name of the command,ksh93
as it usually is, notksh
as chaos said (which is PD Korn on several operating systems, not 93 Korn).
â JdeBP
Sep 3 at 10:44
Why are you demonstrating a 4:59 difference when the title says 5 minutes?
â Jeff Schaller
Sep 3 at 11:47
add a comment |Â
What ksh version do you have?ksh --version
. And can you also use perl or python?
â chaos
Sep 3 at 5:34
ksh --version
is not working for me. I can use perl.
â WaldenSchmidt
Sep 3 at 5:43
chaos is indulging in a little GNU Think. (-: The PD Korn shell does not support--version
. Neither does the MirBSD Korn shell. The bigger clue as to whether one is using 93 Korn is the93
in the name of the command,ksh93
as it usually is, notksh
as chaos said (which is PD Korn on several operating systems, not 93 Korn).
â JdeBP
Sep 3 at 10:44
Why are you demonstrating a 4:59 difference when the title says 5 minutes?
â Jeff Schaller
Sep 3 at 11:47
What ksh version do you have?
ksh --version
. And can you also use perl or python?â chaos
Sep 3 at 5:34
What ksh version do you have?
ksh --version
. And can you also use perl or python?â chaos
Sep 3 at 5:34
ksh --version
is not working for me. I can use perl.â WaldenSchmidt
Sep 3 at 5:43
ksh --version
is not working for me. I can use perl.â WaldenSchmidt
Sep 3 at 5:43
chaos is indulging in a little GNU Think. (-: The PD Korn shell does not support
--version
. Neither does the MirBSD Korn shell. The bigger clue as to whether one is using 93 Korn is the 93
in the name of the command, ksh93
as it usually is, not ksh
as chaos said (which is PD Korn on several operating systems, not 93 Korn).â JdeBP
Sep 3 at 10:44
chaos is indulging in a little GNU Think. (-: The PD Korn shell does not support
--version
. Neither does the MirBSD Korn shell. The bigger clue as to whether one is using 93 Korn is the 93
in the name of the command, ksh93
as it usually is, not ksh
as chaos said (which is PD Korn on several operating systems, not 93 Korn).â JdeBP
Sep 3 at 10:44
Why are you demonstrating a 4:59 difference when the title says 5 minutes?
â Jeff Schaller
Sep 3 at 11:47
Why are you demonstrating a 4:59 difference when the title says 5 minutes?
â Jeff Schaller
Sep 3 at 11:47
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
You could use perl
:
echo $(( $(printf "%(%s)T") - 5 * 60 )) | perl -lne 'print scalar localtime $_'
Or in pure perl:
perl -le 'print scalar localtime(time()-5*60)'
To format use strftime()
:
perl -MPOSIX=strftime -le 'print strftime("%d %h %Y %H:%M:%S", localtime(time()-5*60))'
The second one works. Thanks! Im not familiar with perl. How can I convert it to match the format above?
â WaldenSchmidt
Sep 3 at 6:05
@WaldenSchmidt see my edit
â chaos
Sep 3 at 6:08
Thanks man! This is perfect!
â WaldenSchmidt
Sep 3 at 6:09
add a comment |Â
up vote
5
down vote
bash
actually copied the %(...)T
format from ksh93 but only a small subset.
That's much more powerful in ksh93.
$ date; printf '%(%c)Tn' 'exactly five minutes ago'
Mon 3 Sep 08:08:32 BST 2018
Mon Sep 3 08:03:32 2018
bash
only supports Unix epoch times (or -1
for now, though with recent versions you can also get now with a missing argument) while ksh93 supports complex relative (including English like above, crontab, at
, ISO 8601:2004 durations) or absolute time specifications (see the test data in the source for some examples).
In ksh93
, if you want to pass an epoch time, you use a #
prefix:
$ printf '%(%c)Tn' '#0'
Thu Jan 1 00:00:00 1970
(though here, it happens to give the incorrect time for me in a British timezone where epoch time 0 was at 1am)
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
You could use perl
:
echo $(( $(printf "%(%s)T") - 5 * 60 )) | perl -lne 'print scalar localtime $_'
Or in pure perl:
perl -le 'print scalar localtime(time()-5*60)'
To format use strftime()
:
perl -MPOSIX=strftime -le 'print strftime("%d %h %Y %H:%M:%S", localtime(time()-5*60))'
The second one works. Thanks! Im not familiar with perl. How can I convert it to match the format above?
â WaldenSchmidt
Sep 3 at 6:05
@WaldenSchmidt see my edit
â chaos
Sep 3 at 6:08
Thanks man! This is perfect!
â WaldenSchmidt
Sep 3 at 6:09
add a comment |Â
up vote
2
down vote
accepted
You could use perl
:
echo $(( $(printf "%(%s)T") - 5 * 60 )) | perl -lne 'print scalar localtime $_'
Or in pure perl:
perl -le 'print scalar localtime(time()-5*60)'
To format use strftime()
:
perl -MPOSIX=strftime -le 'print strftime("%d %h %Y %H:%M:%S", localtime(time()-5*60))'
The second one works. Thanks! Im not familiar with perl. How can I convert it to match the format above?
â WaldenSchmidt
Sep 3 at 6:05
@WaldenSchmidt see my edit
â chaos
Sep 3 at 6:08
Thanks man! This is perfect!
â WaldenSchmidt
Sep 3 at 6:09
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
You could use perl
:
echo $(( $(printf "%(%s)T") - 5 * 60 )) | perl -lne 'print scalar localtime $_'
Or in pure perl:
perl -le 'print scalar localtime(time()-5*60)'
To format use strftime()
:
perl -MPOSIX=strftime -le 'print strftime("%d %h %Y %H:%M:%S", localtime(time()-5*60))'
You could use perl
:
echo $(( $(printf "%(%s)T") - 5 * 60 )) | perl -lne 'print scalar localtime $_'
Or in pure perl:
perl -le 'print scalar localtime(time()-5*60)'
To format use strftime()
:
perl -MPOSIX=strftime -le 'print strftime("%d %h %Y %H:%M:%S", localtime(time()-5*60))'
edited Sep 3 at 6:08
answered Sep 3 at 5:52
chaos
34.1k770113
34.1k770113
The second one works. Thanks! Im not familiar with perl. How can I convert it to match the format above?
â WaldenSchmidt
Sep 3 at 6:05
@WaldenSchmidt see my edit
â chaos
Sep 3 at 6:08
Thanks man! This is perfect!
â WaldenSchmidt
Sep 3 at 6:09
add a comment |Â
The second one works. Thanks! Im not familiar with perl. How can I convert it to match the format above?
â WaldenSchmidt
Sep 3 at 6:05
@WaldenSchmidt see my edit
â chaos
Sep 3 at 6:08
Thanks man! This is perfect!
â WaldenSchmidt
Sep 3 at 6:09
The second one works. Thanks! Im not familiar with perl. How can I convert it to match the format above?
â WaldenSchmidt
Sep 3 at 6:05
The second one works. Thanks! Im not familiar with perl. How can I convert it to match the format above?
â WaldenSchmidt
Sep 3 at 6:05
@WaldenSchmidt see my edit
â chaos
Sep 3 at 6:08
@WaldenSchmidt see my edit
â chaos
Sep 3 at 6:08
Thanks man! This is perfect!
â WaldenSchmidt
Sep 3 at 6:09
Thanks man! This is perfect!
â WaldenSchmidt
Sep 3 at 6:09
add a comment |Â
up vote
5
down vote
bash
actually copied the %(...)T
format from ksh93 but only a small subset.
That's much more powerful in ksh93.
$ date; printf '%(%c)Tn' 'exactly five minutes ago'
Mon 3 Sep 08:08:32 BST 2018
Mon Sep 3 08:03:32 2018
bash
only supports Unix epoch times (or -1
for now, though with recent versions you can also get now with a missing argument) while ksh93 supports complex relative (including English like above, crontab, at
, ISO 8601:2004 durations) or absolute time specifications (see the test data in the source for some examples).
In ksh93
, if you want to pass an epoch time, you use a #
prefix:
$ printf '%(%c)Tn' '#0'
Thu Jan 1 00:00:00 1970
(though here, it happens to give the incorrect time for me in a British timezone where epoch time 0 was at 1am)
add a comment |Â
up vote
5
down vote
bash
actually copied the %(...)T
format from ksh93 but only a small subset.
That's much more powerful in ksh93.
$ date; printf '%(%c)Tn' 'exactly five minutes ago'
Mon 3 Sep 08:08:32 BST 2018
Mon Sep 3 08:03:32 2018
bash
only supports Unix epoch times (or -1
for now, though with recent versions you can also get now with a missing argument) while ksh93 supports complex relative (including English like above, crontab, at
, ISO 8601:2004 durations) or absolute time specifications (see the test data in the source for some examples).
In ksh93
, if you want to pass an epoch time, you use a #
prefix:
$ printf '%(%c)Tn' '#0'
Thu Jan 1 00:00:00 1970
(though here, it happens to give the incorrect time for me in a British timezone where epoch time 0 was at 1am)
add a comment |Â
up vote
5
down vote
up vote
5
down vote
bash
actually copied the %(...)T
format from ksh93 but only a small subset.
That's much more powerful in ksh93.
$ date; printf '%(%c)Tn' 'exactly five minutes ago'
Mon 3 Sep 08:08:32 BST 2018
Mon Sep 3 08:03:32 2018
bash
only supports Unix epoch times (or -1
for now, though with recent versions you can also get now with a missing argument) while ksh93 supports complex relative (including English like above, crontab, at
, ISO 8601:2004 durations) or absolute time specifications (see the test data in the source for some examples).
In ksh93
, if you want to pass an epoch time, you use a #
prefix:
$ printf '%(%c)Tn' '#0'
Thu Jan 1 00:00:00 1970
(though here, it happens to give the incorrect time for me in a British timezone where epoch time 0 was at 1am)
bash
actually copied the %(...)T
format from ksh93 but only a small subset.
That's much more powerful in ksh93.
$ date; printf '%(%c)Tn' 'exactly five minutes ago'
Mon 3 Sep 08:08:32 BST 2018
Mon Sep 3 08:03:32 2018
bash
only supports Unix epoch times (or -1
for now, though with recent versions you can also get now with a missing argument) while ksh93 supports complex relative (including English like above, crontab, at
, ISO 8601:2004 durations) or absolute time specifications (see the test data in the source for some examples).
In ksh93
, if you want to pass an epoch time, you use a #
prefix:
$ printf '%(%c)Tn' '#0'
Thu Jan 1 00:00:00 1970
(though here, it happens to give the incorrect time for me in a British timezone where epoch time 0 was at 1am)
edited Sep 3 at 9:47
answered Sep 3 at 7:09
Stéphane Chazelas
286k53527866
286k53527866
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f466487%2fksh-subtract-5-minutes-from-current-time%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
What ksh version do you have?
ksh --version
. And can you also use perl or python?â chaos
Sep 3 at 5:34
ksh --version
is not working for me. I can use perl.â WaldenSchmidt
Sep 3 at 5:43
chaos is indulging in a little GNU Think. (-: The PD Korn shell does not support
--version
. Neither does the MirBSD Korn shell. The bigger clue as to whether one is using 93 Korn is the93
in the name of the command,ksh93
as it usually is, notksh
as chaos said (which is PD Korn on several operating systems, not 93 Korn).â JdeBP
Sep 3 at 10:44
Why are you demonstrating a 4:59 difference when the title says 5 minutes?
â Jeff Schaller
Sep 3 at 11:47