Changing date using bash script

I am trying to change dates in a bash script.

I have a start time and an endtime and want to increment the times. Basically
the month and day have to be incremented in a loop to create two strings, stm and
etm defining the start and end times.

stm="2014-05-13T00:00:00"
etm="2014-05-14T00:00:00"

------ Post updated at 06:33 AM ------

I have started doing this bash details for constructing the start and end strings.

# Covering months May to December 
for m in {5..12}; do
  mth=$((mth+1))
  echo "mth: $mth"
  for dy in {1..30}; do
    day=$((day+1))
    echo "day: $day"
  done
  echo ""
done

# Covering months Jan to April 
for m in {1..4}; do
  mth=$((mth+1))
  echo "mth: $mth"
  for dy in {1..30}; do
    day=$((day+1))
    echo "day: $day"
  done
  echo ""
done

Welcome novilatte,

Sadly I don't know what you are trying to achieve as output here. Can you explain?

Is it homework perhaps? There is a special forum for this.

I could guess that you want a sequence of dates where the month and the day add one each iteration but I'm not sure why.

.... or is it that you want every combination of valid dates for these months. In this case, you are missing the 31st when that occurs and including the 30th February, and taking no account of a leap year.

Would the output from cal be useful?
Can you explain the purpose of this in context? There may be a better way.

Kind regards,
Robin

Hi,
Just an example with command linux date :

$ for i in 1 2 3 4 5 60 3600 86400
> do
> date --date "2014-05-14T00:00:00 $i seconds" "+%Y-%m-%dT%H:%M:%S"
> done
2014-05-14T00:00:01
2014-05-14T00:00:02
2014-05-14T00:00:03
2014-05-14T00:00:04
2014-05-14T00:00:05
2014-05-14T00:01:00
2014-05-14T01:00:00
2014-05-15T00:00:00

Here, I use "seconds", but I would use "minutes", "hours", "days",...

Regards.

I am writing a data request for transfer oe seismological data from a webservice.

------ Post updated at 11:53 AM ------

I shoud be ok with specifying invalid dates (e.g., for february) as then the request will just send me an error code, and not get that data.

This is all interesting, but it still doesn't tell us what you are trying to do nor what output you are trying to produce. Robin asked you several questions in post #2 in this thread that you have not answered.

In what way does producing a list of months 2 through 13 on days 2 through 31 help you define two strings referencing a start time and an end time for an unspecified event.

Knowing that you don't mind creating invalid dates and don't mind losing some of your seismological data is interesting, but it still doesn't tell us what output you're trying to produce nor what that output represents in the real world.

We want to help you reach your goal, but if you don't explain what you're trying to do we are left guessing at what you might be trying to do and are highly unlikely to make a guess that will be of any use to you. Please help us help you!