Xofo
Xofo

Reputation: 1278

What are valid input DATE formats for the (Linux) date command?

The following command generates the date for the next day:

date -d "20150615 12:00 +1 day" +%Y%m%d
20150616

I would like to specify my own INPUT date format, such as:

2015_06_15

But the date command does not like this format and complains about invalid date:

date: invalid date '2015_06_15 12:00 +1 day'

Is it possible to use such a date format? And if so how could I do this.

Upvotes: 4

Views: 10581

Answers (1)

Cyrus
Cyrus

Reputation: 88583

A workaround:

x="2015_06_15"
date -d "${x//_/} 12:00 +1 day" +%Y%m%d

Output:

20150616

Upvotes: 6

Related Questions