0

I 'm using bash I have a date string now, for example:

2015111301 

(yyyymmddHH)

how to get the date string of next hour? that is:

2015111302 
3
  • How are you getting the initial string? Commented Nov 14, 2015 at 9:36
  • @asimovwasright date +%Y%m%d%H can get you such output Commented Nov 14, 2015 at 9:50
  • @Ashish, yes, I know how to get the format, the question was meant for the OP. Commented Nov 14, 2015 at 9:51

2 Answers 2

3

Try this:

in="2015111301" out="$(date -d "${in:0:8} ${in:8:2}:00:00 +1hour" '+%Y%m%d%H')" echo "$out" 

Output:

 2015111302 

See: 3.5.3 Shell Parameter Expansion

Sign up to request clarification or add additional context in comments.

3 Comments

why I am getting 2015111306 output in cygwin
I don't know. Tested with bash 4.2.8 and date from GNU coreutils 8.5.
I am getting same output in Ubuntu 15 LTS now
0

This below script worked for me

#!/bin/bash tempval=$(echo 2015111301 | sed 's/\(.\{8\}\)/\1 /g') tempval=$(echo "$tempval 1 hour") date -d "$tempval" +%Y%m%d%H 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.