Change String to Date with using date -d

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I need to change a date String from format YYYYMMDD to date YYYY-MM-DD without using date -d command. The only option I found is string manipulations.







share|improve this question




















  • How many tools can you name that perform text manipulation? If none, please go and do some basic research. Otherwise, tell us what you’ve tried. … … … … … … … … … … … … … … … … …  P.S. Technically, you have not asked a question.
    – G-Man
    Apr 2 at 15:58















up vote
0
down vote

favorite












I need to change a date String from format YYYYMMDD to date YYYY-MM-DD without using date -d command. The only option I found is string manipulations.







share|improve this question




















  • How many tools can you name that perform text manipulation? If none, please go and do some basic research. Otherwise, tell us what you’ve tried. … … … … … … … … … … … … … … … … …  P.S. Technically, you have not asked a question.
    – G-Man
    Apr 2 at 15:58













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I need to change a date String from format YYYYMMDD to date YYYY-MM-DD without using date -d command. The only option I found is string manipulations.







share|improve this question












I need to change a date String from format YYYYMMDD to date YYYY-MM-DD without using date -d command. The only option I found is string manipulations.









share|improve this question











share|improve this question




share|improve this question










asked Apr 2 at 15:33









Hassam

63




63











  • How many tools can you name that perform text manipulation? If none, please go and do some basic research. Otherwise, tell us what you’ve tried. … … … … … … … … … … … … … … … … …  P.S. Technically, you have not asked a question.
    – G-Man
    Apr 2 at 15:58

















  • How many tools can you name that perform text manipulation? If none, please go and do some basic research. Otherwise, tell us what you’ve tried. … … … … … … … … … … … … … … … … …  P.S. Technically, you have not asked a question.
    – G-Man
    Apr 2 at 15:58
















How many tools can you name that perform text manipulation? If none, please go and do some basic research. Otherwise, tell us what you’ve tried. … … … … … … … … … … … … … … … … …  P.S. Technically, you have not asked a question.
– G-Man
Apr 2 at 15:58





How many tools can you name that perform text manipulation? If none, please go and do some basic research. Otherwise, tell us what you’ve tried. … … … … … … … … … … … … … … … … …  P.S. Technically, you have not asked a question.
– G-Man
Apr 2 at 15:58











1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










What about using bash parameter expansion?



$ var=20180402
$ echo "$var::4-$var:4:2-$var:6"
2018-04-02





share|improve this answer






















  • Spot of code golf: the last term could just be '$var:6'
    – bu5hman
    Apr 2 at 17:10










  • Further golf : the first term could be just $var::4
    – steve
    Apr 2 at 18:33










  • Thanks didn't think about either. I did consider using $var: -2 for the last one but didn't want to lead to confusion.
    – Jesse_b
    Apr 2 at 19:17










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',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f435069%2fchange-string-to-date-with-using-date-d%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










What about using bash parameter expansion?



$ var=20180402
$ echo "$var::4-$var:4:2-$var:6"
2018-04-02





share|improve this answer






















  • Spot of code golf: the last term could just be '$var:6'
    – bu5hman
    Apr 2 at 17:10










  • Further golf : the first term could be just $var::4
    – steve
    Apr 2 at 18:33










  • Thanks didn't think about either. I did consider using $var: -2 for the last one but didn't want to lead to confusion.
    – Jesse_b
    Apr 2 at 19:17














up vote
3
down vote



accepted










What about using bash parameter expansion?



$ var=20180402
$ echo "$var::4-$var:4:2-$var:6"
2018-04-02





share|improve this answer






















  • Spot of code golf: the last term could just be '$var:6'
    – bu5hman
    Apr 2 at 17:10










  • Further golf : the first term could be just $var::4
    – steve
    Apr 2 at 18:33










  • Thanks didn't think about either. I did consider using $var: -2 for the last one but didn't want to lead to confusion.
    – Jesse_b
    Apr 2 at 19:17












up vote
3
down vote



accepted







up vote
3
down vote



accepted






What about using bash parameter expansion?



$ var=20180402
$ echo "$var::4-$var:4:2-$var:6"
2018-04-02





share|improve this answer














What about using bash parameter expansion?



$ var=20180402
$ echo "$var::4-$var:4:2-$var:6"
2018-04-02






share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 2 at 19:16

























answered Apr 2 at 15:36









Jesse_b

10.4k22658




10.4k22658











  • Spot of code golf: the last term could just be '$var:6'
    – bu5hman
    Apr 2 at 17:10










  • Further golf : the first term could be just $var::4
    – steve
    Apr 2 at 18:33










  • Thanks didn't think about either. I did consider using $var: -2 for the last one but didn't want to lead to confusion.
    – Jesse_b
    Apr 2 at 19:17
















  • Spot of code golf: the last term could just be '$var:6'
    – bu5hman
    Apr 2 at 17:10










  • Further golf : the first term could be just $var::4
    – steve
    Apr 2 at 18:33










  • Thanks didn't think about either. I did consider using $var: -2 for the last one but didn't want to lead to confusion.
    – Jesse_b
    Apr 2 at 19:17















Spot of code golf: the last term could just be '$var:6'
– bu5hman
Apr 2 at 17:10




Spot of code golf: the last term could just be '$var:6'
– bu5hman
Apr 2 at 17:10












Further golf : the first term could be just $var::4
– steve
Apr 2 at 18:33




Further golf : the first term could be just $var::4
– steve
Apr 2 at 18:33












Thanks didn't think about either. I did consider using $var: -2 for the last one but didn't want to lead to confusion.
– Jesse_b
Apr 2 at 19:17




Thanks didn't think about either. I did consider using $var: -2 for the last one but didn't want to lead to confusion.
– Jesse_b
Apr 2 at 19:17












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f435069%2fchange-string-to-date-with-using-date-d%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Christian Cage

How to properly install USB display driver for Fresco Logic FL2000DX on Ubuntu?