Unix/Linux command to get the future time for the any given time value
I have used the below commands to find the 30 mins older time but not able to frame commands to add 30 mins.
Sample structure of input.
dateinput=20181214202959
inputTime=$(echo $dateinput | sed 's,(.{4})(.{2})(.{2})(.{2})(.{2}),1-2-3 4:5:,')
param2=`date '+%Y%m%d%H%M%S' --date="$inputTime 30 minutes ago"`
echo $param2
20181214195959
Please let me know the steps to add 30 mins similar to the above one. For the sample dateinput given above the desired output is 20181214205959.
With the direct date command I am able to add and reduce based on the requirement like given below :
$date
Tue Dec 18 20:49:06 PST 2018
$date --date "-30 minutes"
Tue Dec 18 20:18:55 PST 2018
$date --date "+30 minutes"
Tue Dec 18 21:19:01 PST 2018
But my requirement is to get the date from the input which will be given like 20181214202959 which is in YYYYMMDDhhmmss format. This is where I am facing issues. Able to reduce the time using "30 minutes ago" command but not able to get the future value for the given time.
linux date
add a comment |
I have used the below commands to find the 30 mins older time but not able to frame commands to add 30 mins.
Sample structure of input.
dateinput=20181214202959
inputTime=$(echo $dateinput | sed 's,(.{4})(.{2})(.{2})(.{2})(.{2}),1-2-3 4:5:,')
param2=`date '+%Y%m%d%H%M%S' --date="$inputTime 30 minutes ago"`
echo $param2
20181214195959
Please let me know the steps to add 30 mins similar to the above one. For the sample dateinput given above the desired output is 20181214205959.
With the direct date command I am able to add and reduce based on the requirement like given below :
$date
Tue Dec 18 20:49:06 PST 2018
$date --date "-30 minutes"
Tue Dec 18 20:18:55 PST 2018
$date --date "+30 minutes"
Tue Dec 18 21:19:01 PST 2018
But my requirement is to get the date from the input which will be given like 20181214202959 which is in YYYYMMDDhhmmss format. This is where I am facing issues. Able to reduce the time using "30 minutes ago" command but not able to get the future value for the given time.
linux date
add a comment |
I have used the below commands to find the 30 mins older time but not able to frame commands to add 30 mins.
Sample structure of input.
dateinput=20181214202959
inputTime=$(echo $dateinput | sed 's,(.{4})(.{2})(.{2})(.{2})(.{2}),1-2-3 4:5:,')
param2=`date '+%Y%m%d%H%M%S' --date="$inputTime 30 minutes ago"`
echo $param2
20181214195959
Please let me know the steps to add 30 mins similar to the above one. For the sample dateinput given above the desired output is 20181214205959.
With the direct date command I am able to add and reduce based on the requirement like given below :
$date
Tue Dec 18 20:49:06 PST 2018
$date --date "-30 minutes"
Tue Dec 18 20:18:55 PST 2018
$date --date "+30 minutes"
Tue Dec 18 21:19:01 PST 2018
But my requirement is to get the date from the input which will be given like 20181214202959 which is in YYYYMMDDhhmmss format. This is where I am facing issues. Able to reduce the time using "30 minutes ago" command but not able to get the future value for the given time.
linux date
I have used the below commands to find the 30 mins older time but not able to frame commands to add 30 mins.
Sample structure of input.
dateinput=20181214202959
inputTime=$(echo $dateinput | sed 's,(.{4})(.{2})(.{2})(.{2})(.{2}),1-2-3 4:5:,')
param2=`date '+%Y%m%d%H%M%S' --date="$inputTime 30 minutes ago"`
echo $param2
20181214195959
Please let me know the steps to add 30 mins similar to the above one. For the sample dateinput given above the desired output is 20181214205959.
With the direct date command I am able to add and reduce based on the requirement like given below :
$date
Tue Dec 18 20:49:06 PST 2018
$date --date "-30 minutes"
Tue Dec 18 20:18:55 PST 2018
$date --date "+30 minutes"
Tue Dec 18 21:19:01 PST 2018
But my requirement is to get the date from the input which will be given like 20181214202959 which is in YYYYMMDDhhmmss format. This is where I am facing issues. Able to reduce the time using "30 minutes ago" command but not able to get the future value for the given time.
linux date
linux date
asked Dec 19 '18 at 4:58
Sekar Ramu
54
54
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Your code
dateinput=20181214202959
inputTime=$(echo $dateinput | sed 's,(.{4})(.{2})(.{2})(.{2})(.{2}),1-2-3 4:5:,')
adds spacing to dateinput to set inputTime
to 2018-12-14 20:59:39
.
You then are running date --date="2018-12-14 20:59:59 30 minutes ago"
asking for a particular output format.
If you remove the ago
from the request you will ask for the time 30 minutes in the future. The effect of the word ago
is to negate the most recent time offset. In general you can list a number of time offsets and these are all added, so you can combine for example a number of minutes and a number of weeks.
$ date --date="2018-12-14 20:00:00 30 minutes ago 1 week"
Fri Dec 21 19:30:00 PST 2018
$ date --date="2018-12-14 20:00:00 30 minutes 1 week"
Fri Dec 21 20:30:00 PST 2018
$ date --date="2018-12-14 20:00:00 30 minutes 1 week ago"
Fri Dec 7 20:30:00 PST 2018
Thanks buddy, tried hell lot of things but missed to try this :)
– Sekar Ramu
Dec 19 '18 at 6:01
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f489823%2funix-linux-command-to-get-the-future-time-for-the-any-given-time-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your code
dateinput=20181214202959
inputTime=$(echo $dateinput | sed 's,(.{4})(.{2})(.{2})(.{2})(.{2}),1-2-3 4:5:,')
adds spacing to dateinput to set inputTime
to 2018-12-14 20:59:39
.
You then are running date --date="2018-12-14 20:59:59 30 minutes ago"
asking for a particular output format.
If you remove the ago
from the request you will ask for the time 30 minutes in the future. The effect of the word ago
is to negate the most recent time offset. In general you can list a number of time offsets and these are all added, so you can combine for example a number of minutes and a number of weeks.
$ date --date="2018-12-14 20:00:00 30 minutes ago 1 week"
Fri Dec 21 19:30:00 PST 2018
$ date --date="2018-12-14 20:00:00 30 minutes 1 week"
Fri Dec 21 20:30:00 PST 2018
$ date --date="2018-12-14 20:00:00 30 minutes 1 week ago"
Fri Dec 7 20:30:00 PST 2018
Thanks buddy, tried hell lot of things but missed to try this :)
– Sekar Ramu
Dec 19 '18 at 6:01
add a comment |
Your code
dateinput=20181214202959
inputTime=$(echo $dateinput | sed 's,(.{4})(.{2})(.{2})(.{2})(.{2}),1-2-3 4:5:,')
adds spacing to dateinput to set inputTime
to 2018-12-14 20:59:39
.
You then are running date --date="2018-12-14 20:59:59 30 minutes ago"
asking for a particular output format.
If you remove the ago
from the request you will ask for the time 30 minutes in the future. The effect of the word ago
is to negate the most recent time offset. In general you can list a number of time offsets and these are all added, so you can combine for example a number of minutes and a number of weeks.
$ date --date="2018-12-14 20:00:00 30 minutes ago 1 week"
Fri Dec 21 19:30:00 PST 2018
$ date --date="2018-12-14 20:00:00 30 minutes 1 week"
Fri Dec 21 20:30:00 PST 2018
$ date --date="2018-12-14 20:00:00 30 minutes 1 week ago"
Fri Dec 7 20:30:00 PST 2018
Thanks buddy, tried hell lot of things but missed to try this :)
– Sekar Ramu
Dec 19 '18 at 6:01
add a comment |
Your code
dateinput=20181214202959
inputTime=$(echo $dateinput | sed 's,(.{4})(.{2})(.{2})(.{2})(.{2}),1-2-3 4:5:,')
adds spacing to dateinput to set inputTime
to 2018-12-14 20:59:39
.
You then are running date --date="2018-12-14 20:59:59 30 minutes ago"
asking for a particular output format.
If you remove the ago
from the request you will ask for the time 30 minutes in the future. The effect of the word ago
is to negate the most recent time offset. In general you can list a number of time offsets and these are all added, so you can combine for example a number of minutes and a number of weeks.
$ date --date="2018-12-14 20:00:00 30 minutes ago 1 week"
Fri Dec 21 19:30:00 PST 2018
$ date --date="2018-12-14 20:00:00 30 minutes 1 week"
Fri Dec 21 20:30:00 PST 2018
$ date --date="2018-12-14 20:00:00 30 minutes 1 week ago"
Fri Dec 7 20:30:00 PST 2018
Your code
dateinput=20181214202959
inputTime=$(echo $dateinput | sed 's,(.{4})(.{2})(.{2})(.{2})(.{2}),1-2-3 4:5:,')
adds spacing to dateinput to set inputTime
to 2018-12-14 20:59:39
.
You then are running date --date="2018-12-14 20:59:59 30 minutes ago"
asking for a particular output format.
If you remove the ago
from the request you will ask for the time 30 minutes in the future. The effect of the word ago
is to negate the most recent time offset. In general you can list a number of time offsets and these are all added, so you can combine for example a number of minutes and a number of weeks.
$ date --date="2018-12-14 20:00:00 30 minutes ago 1 week"
Fri Dec 21 19:30:00 PST 2018
$ date --date="2018-12-14 20:00:00 30 minutes 1 week"
Fri Dec 21 20:30:00 PST 2018
$ date --date="2018-12-14 20:00:00 30 minutes 1 week ago"
Fri Dec 7 20:30:00 PST 2018
answered Dec 19 '18 at 5:32
icarus
5,6611929
5,6611929
Thanks buddy, tried hell lot of things but missed to try this :)
– Sekar Ramu
Dec 19 '18 at 6:01
add a comment |
Thanks buddy, tried hell lot of things but missed to try this :)
– Sekar Ramu
Dec 19 '18 at 6:01
Thanks buddy, tried hell lot of things but missed to try this :)
– Sekar Ramu
Dec 19 '18 at 6:01
Thanks buddy, tried hell lot of things but missed to try this :)
– Sekar Ramu
Dec 19 '18 at 6:01
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f489823%2funix-linux-command-to-get-the-future-time-for-the-any-given-time-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown