Bash Script Convert Julian Date To A Calendar Date

There are some options for doing this job in the R package date. See for example on page 4, the function date.mmddyy, which says. Given a vector of Julian dates, this returns them in the form “10/11/89”, “28/7/54”, etc. Algorithms are extensively described so I will just point you to the two most useful pages – Julian day/Wikipedia and Julian Day Numbers/UT. After a short while I wrote a shell script to convert between Gregorian calendar date and Julian Day Number.

In this tutorial, we will learn the available format options for date command and how to format a date in Bash Scripting, with examples.

Bash Date

To format Bash Date to a required one, bash shell provides date command along with many format options.

Bash Date Command

Following is the syntax of date command

Format Bash Date with Options

As already said, you can format the Bash Date. And the format you wish may contain spaces as well.

Bash script convert julian date to a calendar date 2020

Date command accepts options if provided any

Bash Script Convert Julian Date To A Calendar Date

To format date with spaces, use the syntax

List of Bash Date Formatting Options

Following are the list of available options for date command :

You may use any of the above-mentioned format options (first column) for the date command in the aforementioned syntax.

Examples

Bash Date Format MM-DD-YYYY

To format date in MM-DD-YYYY format, use the command date +%m-%d-%Y.

Bash Script

Output

Please observe the upper and lower case letters : %m for month, %d for day and %Y for year. %M would mean minutes.

Bash Date Format MM-YYYY

To format date in MM-YYYY format, use the command date +%m-%Y .

Bash Script

Output

Bash Date Format: Weekday DD-Month, YYYY

To format date in MM-DD-YYYY format, use the command date +%m-%d-%Y.

Bash Script

Script

Bash Script Convert Julian Date To A Calendar Date 2019

Output

Conclusion

Bash Script Convert Julian Date To A Calendar Date

Concluding this Bash Tutorial – Bash Date, we have learned to use date command, the list of Bash Date Format options available with the date command and some of the examples demonstrating the usage of the format options.

Comments are closed.