Convert Date string in timestampBash : compare two strings with spaceLeap seconds and dateIssues with storing...
What is the fastest way to level past 95 in Diablo II?
What should we do with manuals from the 80s?
Will some rockets really collapse under their own weight?
Duplicate and slide edge (rip from boundary)
Understanding a part of the proof that sequence that converges to square root of two is decreasing.
Meaning of だけはわからない
Is this bar slide trick shown on Cheers real or a visual effect?
When did Bilbo and Frodo learn that Gandalf was a Maia?
Can anyone help me what's wrong here as i can prove 0 = 1?
When does The Truman Show take place?
Why does Japan use the same type of AC power outlet as the US?
Does writing regular diary entries count as writing practice?
Why is the battery jumpered to a resistor in this schematic?
Can I use my OWN published papers' images in my thesis without Copyright infringment
May the tower use the runway while an emergency aircraft is inbound?
Is there a word for returning to unpreparedness?
Adding things to bunches of things vs multiplication
Why does "auf der Strecke bleiben" mean "to fall by the wayside"?
What is the opposite of "hunger level"?
Did Michelle Obama have a staff of 23; and Melania have a staff of 4?
What are these panels underneath the wing root of a A380?
Good way to stop electrolyte tabs from turning into powder?
How would armour (and combat) change if the fighter didn't need to actually wear it?
Is Fourier series a sampled version of Fourier transform?
Convert Date string in timestamp
Bash : compare two strings with spaceLeap seconds and dateIssues with storing an echo of a date conversion into a string variable inunixScript using user input to calculate old datePopulate array with a sed/echo combinationHow to convert date to timestampConvert string dateHow can I calculate and format a date duration using GNU tools, not a result date?Bash command to rename files and convert datestamp from 'dd[st/nd/rd/th] mmm yyyy' to 'yyyymmdd'?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I can't find the right syntax to convert a string date in epoch timestamp.
The script is:
date -d '2012-03-02 22:00 EDT' +%s
DATEJ=`echo -n '2012-03-02 22:00'`
echo $DATEJ
date -d $DATEJ EDT +%s
and the result is
[gg@raspi8 ~]$ CNVDATTS
1330740000
'2012-03-02 22:00'
date: opérande supplémentaire « EDT »
Saisissez « date --help » pour plus d'informations.
Where is the fault?
It seems that the variable DATEJ
does not give the same as the string in the 1st line. If I don't write EDT
, the error is same but mention +%s
.
bash date syntax
New contributor
add a comment |
I can't find the right syntax to convert a string date in epoch timestamp.
The script is:
date -d '2012-03-02 22:00 EDT' +%s
DATEJ=`echo -n '2012-03-02 22:00'`
echo $DATEJ
date -d $DATEJ EDT +%s
and the result is
[gg@raspi8 ~]$ CNVDATTS
1330740000
'2012-03-02 22:00'
date: opérande supplémentaire « EDT »
Saisissez « date --help » pour plus d'informations.
Where is the fault?
It seems that the variable DATEJ
does not give the same as the string in the 1st line. If I don't write EDT
, the error is same but mention +%s
.
bash date syntax
New contributor
What type of Unix are you running on?
– Kusalananda♦
yesterday
1
what's the point of theecho -n
? why not justDATEJ='2012-03-02 22:00'
? Also, you need double-quotes when you use $DATEJ - e.g.date -d "$DATEJ EDT" +%s
, otherwisedate
will get three arguments$DATEJ
,EDT
, and+%s
instead of two....that's why it's complaining about the extra argument (i don't speak or read french but i can make an uneducated guess :)
– cas
yesterday
add a comment |
I can't find the right syntax to convert a string date in epoch timestamp.
The script is:
date -d '2012-03-02 22:00 EDT' +%s
DATEJ=`echo -n '2012-03-02 22:00'`
echo $DATEJ
date -d $DATEJ EDT +%s
and the result is
[gg@raspi8 ~]$ CNVDATTS
1330740000
'2012-03-02 22:00'
date: opérande supplémentaire « EDT »
Saisissez « date --help » pour plus d'informations.
Where is the fault?
It seems that the variable DATEJ
does not give the same as the string in the 1st line. If I don't write EDT
, the error is same but mention +%s
.
bash date syntax
New contributor
I can't find the right syntax to convert a string date in epoch timestamp.
The script is:
date -d '2012-03-02 22:00 EDT' +%s
DATEJ=`echo -n '2012-03-02 22:00'`
echo $DATEJ
date -d $DATEJ EDT +%s
and the result is
[gg@raspi8 ~]$ CNVDATTS
1330740000
'2012-03-02 22:00'
date: opérande supplémentaire « EDT »
Saisissez « date --help » pour plus d'informations.
Where is the fault?
It seems that the variable DATEJ
does not give the same as the string in the 1st line. If I don't write EDT
, the error is same but mention +%s
.
bash date syntax
bash date syntax
New contributor
New contributor
edited yesterday
Bart
1,2041 gold badge3 silver badges18 bronze badges
1,2041 gold badge3 silver badges18 bronze badges
New contributor
asked yesterday
Georges GuinchardGeorges Guinchard
4
4
New contributor
New contributor
What type of Unix are you running on?
– Kusalananda♦
yesterday
1
what's the point of theecho -n
? why not justDATEJ='2012-03-02 22:00'
? Also, you need double-quotes when you use $DATEJ - e.g.date -d "$DATEJ EDT" +%s
, otherwisedate
will get three arguments$DATEJ
,EDT
, and+%s
instead of two....that's why it's complaining about the extra argument (i don't speak or read french but i can make an uneducated guess :)
– cas
yesterday
add a comment |
What type of Unix are you running on?
– Kusalananda♦
yesterday
1
what's the point of theecho -n
? why not justDATEJ='2012-03-02 22:00'
? Also, you need double-quotes when you use $DATEJ - e.g.date -d "$DATEJ EDT" +%s
, otherwisedate
will get three arguments$DATEJ
,EDT
, and+%s
instead of two....that's why it's complaining about the extra argument (i don't speak or read french but i can make an uneducated guess :)
– cas
yesterday
What type of Unix are you running on?
– Kusalananda♦
yesterday
What type of Unix are you running on?
– Kusalananda♦
yesterday
1
1
what's the point of the
echo -n
? why not just DATEJ='2012-03-02 22:00'
? Also, you need double-quotes when you use $DATEJ - e.g. date -d "$DATEJ EDT" +%s
, otherwise date
will get three arguments $DATEJ
, EDT
, and +%s
instead of two....that's why it's complaining about the extra argument (i don't speak or read french but i can make an uneducated guess :)– cas
yesterday
what's the point of the
echo -n
? why not just DATEJ='2012-03-02 22:00'
? Also, you need double-quotes when you use $DATEJ - e.g. date -d "$DATEJ EDT" +%s
, otherwise date
will get three arguments $DATEJ
, EDT
, and +%s
instead of two....that's why it's complaining about the extra argument (i don't speak or read french but i can make an uneducated guess :)– cas
yesterday
add a comment |
1 Answer
1
active
oldest
votes
The problem here seems to be with the single-quotes in $DATEJ
. Your variable imposes them.
Change that to
DATEJ=`echo -n "2012-03-02 22:00"`
and in the final command:
date -d "$DATEJ EDT" +%s
This will work:
$ date -d '2012-03-02 22:00 EDT' +%s
1330740000
$ DATEJ=`echo -n "2012-03-02 22:00"`
$ echo $DATEJ
2012-03-02 22:00
$ date -d "$DATEJ EDT" +%s
1330740000
EDIT
Actually, you don't need to echo
the date, unless your script imposes so, so the variable $DATEJ
can simply be put as
DATEJ="2012-03-02 22:00"
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
});
}
});
Georges Guinchard is a new contributor. Be nice, and check out our Code of Conduct.
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%2f535714%2fconvert-date-string-in-timestamp%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
The problem here seems to be with the single-quotes in $DATEJ
. Your variable imposes them.
Change that to
DATEJ=`echo -n "2012-03-02 22:00"`
and in the final command:
date -d "$DATEJ EDT" +%s
This will work:
$ date -d '2012-03-02 22:00 EDT' +%s
1330740000
$ DATEJ=`echo -n "2012-03-02 22:00"`
$ echo $DATEJ
2012-03-02 22:00
$ date -d "$DATEJ EDT" +%s
1330740000
EDIT
Actually, you don't need to echo
the date, unless your script imposes so, so the variable $DATEJ
can simply be put as
DATEJ="2012-03-02 22:00"
add a comment |
The problem here seems to be with the single-quotes in $DATEJ
. Your variable imposes them.
Change that to
DATEJ=`echo -n "2012-03-02 22:00"`
and in the final command:
date -d "$DATEJ EDT" +%s
This will work:
$ date -d '2012-03-02 22:00 EDT' +%s
1330740000
$ DATEJ=`echo -n "2012-03-02 22:00"`
$ echo $DATEJ
2012-03-02 22:00
$ date -d "$DATEJ EDT" +%s
1330740000
EDIT
Actually, you don't need to echo
the date, unless your script imposes so, so the variable $DATEJ
can simply be put as
DATEJ="2012-03-02 22:00"
add a comment |
The problem here seems to be with the single-quotes in $DATEJ
. Your variable imposes them.
Change that to
DATEJ=`echo -n "2012-03-02 22:00"`
and in the final command:
date -d "$DATEJ EDT" +%s
This will work:
$ date -d '2012-03-02 22:00 EDT' +%s
1330740000
$ DATEJ=`echo -n "2012-03-02 22:00"`
$ echo $DATEJ
2012-03-02 22:00
$ date -d "$DATEJ EDT" +%s
1330740000
EDIT
Actually, you don't need to echo
the date, unless your script imposes so, so the variable $DATEJ
can simply be put as
DATEJ="2012-03-02 22:00"
The problem here seems to be with the single-quotes in $DATEJ
. Your variable imposes them.
Change that to
DATEJ=`echo -n "2012-03-02 22:00"`
and in the final command:
date -d "$DATEJ EDT" +%s
This will work:
$ date -d '2012-03-02 22:00 EDT' +%s
1330740000
$ DATEJ=`echo -n "2012-03-02 22:00"`
$ echo $DATEJ
2012-03-02 22:00
$ date -d "$DATEJ EDT" +%s
1330740000
EDIT
Actually, you don't need to echo
the date, unless your script imposes so, so the variable $DATEJ
can simply be put as
DATEJ="2012-03-02 22:00"
answered yesterday
BartBart
1,2041 gold badge3 silver badges18 bronze badges
1,2041 gold badge3 silver badges18 bronze badges
add a comment |
add a comment |
Georges Guinchard is a new contributor. Be nice, and check out our Code of Conduct.
Georges Guinchard is a new contributor. Be nice, and check out our Code of Conduct.
Georges Guinchard is a new contributor. Be nice, and check out our Code of Conduct.
Georges Guinchard is a new contributor. Be nice, and check out our Code of Conduct.
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.
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%2f535714%2fconvert-date-string-in-timestamp%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
What type of Unix are you running on?
– Kusalananda♦
yesterday
1
what's the point of the
echo -n
? why not justDATEJ='2012-03-02 22:00'
? Also, you need double-quotes when you use $DATEJ - e.g.date -d "$DATEJ EDT" +%s
, otherwisedate
will get three arguments$DATEJ
,EDT
, and+%s
instead of two....that's why it's complaining about the extra argument (i don't speak or read french but i can make an uneducated guess :)– cas
yesterday