Skip to main content
Added solution to "a list of date commands".
Source Link
user232326
user232326

The correct format for a date-time that will be correctly parsed by GNU date is:

$ LC_ALL=C TZ=UTC0 date +"%Y-%m-%dT%H:%M:%S%z" 2016-09-28T04:08:55+0000 

And that avoids spaces also, which may generate other problems.

If your file contains one line per date like:

$ cat dates.txt 1992-03-28T14:26:01+0000 2004-02-29T21:02:02+0000 2005-02-28T21:02:03+0000 2015-07-02T11:52:04+0000 2016-03-31T01:36:05+0000 

Then this will work:

$ TZ=America/Los_Angeles date -f infile Sat Mar 28 06:26:01 PST 1992 Sun Feb 29 13:02:02 PST 2004 Mon Feb 28 13:02:03 PST 2005 Thu Jul 2 04:52:04 PDT 2015 Wed Mar 30 18:36:05 PDT 2016 


If what you want to do is create a file with "date commands" as in:

$ cat dates.txt date -d "1992-03-28T14:26:01+0000" date -d "2004-02-29T21:02:02+0000" LC_ALL=C TZ=UTC0 date -d "2005-02-28T21:02:03+0000" +"%Y-%m-%d" TZ=America/Los_Angeles date -d "2005-02-28T21:02:03+0000" date -d "2015-07-02T11:52:04+0000" date -d "2016-03-31T01:36:05+0000" 

Then you need to execute each line with the shell.
One fast solution is to source the file and all commands will be excuted.

$ . ./dates.txt Sat Mar 28 14:26:01 GMT 1992 Sun Feb 29 21:02:02 GMT 2004 2005-02-28 Mon Feb 28 13:02:03 PST 2005 Thu Jul 2 11:52:04 GMT 2015 Thu Mar 31 01:36:05 GMT 2016 

Does this answer your question?

The correct format for a date-time that will be correctly parsed by GNU date is:

$ LC_ALL=C TZ=UTC0 date +"%Y-%m-%dT%H:%M:%S%z" 2016-09-28T04:08:55+0000 

And that avoids spaces also, which may generate other problems.

If your file contains one line per date like:

$ cat dates.txt 1992-03-28T14:26:01+0000 2004-02-29T21:02:02+0000 2005-02-28T21:02:03+0000 2015-07-02T11:52:04+0000 2016-03-31T01:36:05+0000 

Then this will work:

$ TZ=America/Los_Angeles date -f infile Sat Mar 28 06:26:01 PST 1992 Sun Feb 29 13:02:02 PST 2004 Mon Feb 28 13:02:03 PST 2005 Thu Jul 2 04:52:04 PDT 2015 Wed Mar 30 18:36:05 PDT 2016 

The correct format for a date-time that will be correctly parsed by GNU date is:

$ LC_ALL=C TZ=UTC0 date +"%Y-%m-%dT%H:%M:%S%z" 2016-09-28T04:08:55+0000 

And that avoids spaces also, which may generate other problems.

If your file contains one line per date like:

$ cat dates.txt 1992-03-28T14:26:01+0000 2004-02-29T21:02:02+0000 2005-02-28T21:02:03+0000 2015-07-02T11:52:04+0000 2016-03-31T01:36:05+0000 

Then this will work:

$ TZ=America/Los_Angeles date -f infile Sat Mar 28 06:26:01 PST 1992 Sun Feb 29 13:02:02 PST 2004 Mon Feb 28 13:02:03 PST 2005 Thu Jul 2 04:52:04 PDT 2015 Wed Mar 30 18:36:05 PDT 2016 


If what you want to do is create a file with "date commands" as in:

$ cat dates.txt date -d "1992-03-28T14:26:01+0000" date -d "2004-02-29T21:02:02+0000" LC_ALL=C TZ=UTC0 date -d "2005-02-28T21:02:03+0000" +"%Y-%m-%d" TZ=America/Los_Angeles date -d "2005-02-28T21:02:03+0000" date -d "2015-07-02T11:52:04+0000" date -d "2016-03-31T01:36:05+0000" 

Then you need to execute each line with the shell.
One fast solution is to source the file and all commands will be excuted.

$ . ./dates.txt Sat Mar 28 14:26:01 GMT 1992 Sun Feb 29 21:02:02 GMT 2004 2005-02-28 Mon Feb 28 13:02:03 PST 2005 Thu Jul 2 11:52:04 GMT 2015 Thu Mar 31 01:36:05 GMT 2016 

Does this answer your question?

Source Link
user232326
user232326

The correct format for a date-time that will be correctly parsed by GNU date is:

$ LC_ALL=C TZ=UTC0 date +"%Y-%m-%dT%H:%M:%S%z" 2016-09-28T04:08:55+0000 

And that avoids spaces also, which may generate other problems.

If your file contains one line per date like:

$ cat dates.txt 1992-03-28T14:26:01+0000 2004-02-29T21:02:02+0000 2005-02-28T21:02:03+0000 2015-07-02T11:52:04+0000 2016-03-31T01:36:05+0000 

Then this will work:

$ TZ=America/Los_Angeles date -f infile Sat Mar 28 06:26:01 PST 1992 Sun Feb 29 13:02:02 PST 2004 Mon Feb 28 13:02:03 PST 2005 Thu Jul 2 04:52:04 PDT 2015 Wed Mar 30 18:36:05 PDT 2016