1. Bash Script Convert Julian Date To A Calendar Date 2019
  2. Convert Julian Date To Calendar Date In Unix
  3. Bash Script Convert Julian Date To A Calendar Date Today
  4. Bash Script Convert Julian Date To A Calendar Date

Here's a ksh function to convert a Gregorian date of the form MM/DD/YY to
a Julian date of form YYDDD:

A Julian date is the number of days and fractional days since noon on November 24, 4714 BCE in the proleptic Gregorian calendar, or January 1, 4713 BCE in the proleptic Julian calendar. If dateType is 'modifiedjuliandate', then juliandate converts the datetime values in t to the equivalent modified Julian dates. Julian Day Converter is a webpage with JavaScript code to convert a Julian date to Gregorian calendar date. Use View - Source in your browser to see the source code of the JavaScript function which converts the Julian date to Gregorian date. You can use this function slightly adapted with some additional UltraEdit script commands to make the.

function julian # <MM/DD/YY>
{
typeset ifs=$IFS IFS='/'
set -- $1
IFS=$ifs
integer mm=$1 dd=$2 yy=$3
typeset -RZ3 jjj

((yy/4*4yy)) &&
set -- 0 31 60 91 121 152 182 213 244 274 305 335 ||
set -- 0 31 59 90 120 151 181 212 243 273 304 334

eval '((jjj=${'$mm'}+dd))'
print $yy$jjj

On reading your request again, however, it seems like what you want is
something that converts the last-modified date of a file to Julian.
This is difficult at best in the Korn shell. If you have perl, it's easy:

ls *.ext |
perl -lne '
$file = $_;
(warn('couldnt stat $file: $!n'), next) unless $mtime = (stat($file))[9];
$jdate = sprintf('%.2d%.3d', (localtime($mtime))[5,7]);
($newname = $file) =~ s/[.].*$/.$jdate/;
warn 'couldnt rename $file to $newname: $!n' unless rename($file, $newname);
'

This renames any files listed by the ls of form <file>.ext to <file>.YYDDD,
where YYDDD is the Julian date it was last modified on.

If you don't know perl, don't let it scare you. It's a great language.
See comp.lang.perl for more details.

Hope this helps,

John.

I often get asked how to convert a datetime into Julian Date format in T-SQL. People have differing opinions about what Julian means, but the one I got asked about most recently meant YYDDD, as often used by mainframe systems (I think this is Julian Date, as opposed to Julian Day which is the number of days since 4713BC). SQL Server doesn’t have a TO_JULIAN function, but we can make one easily enough.

CalendarScript

So we’re wanting to express a date as YYDDD, where YY is the two-digit form of the year, and DDD is the number of days since Dec 31st of the previous year (ie, the DDDth day of the year).

Using the DATEPART function can get each part. YY for the year, and DY for the day of the year. I’m going to use @date as a variable here, of type datetime. Using the date type in SQL 2008 would work just the same.

Bash Script Convert Julian Date To A Calendar DateBash script convert julian date to a calendar date 2020

Bash Script Convert Julian Date To A Calendar Date 2019

SELECT DATEPART(yy, @date), DATEPART(dy, @date)

However, to make sure that we have the year in two-digits only, we should convert this to a string and get the rightmost two characters.

Bash script convert julian date to a calendar date today

SELECT RIGHT(CAST(DATEPART(yy, @date) AS char(4)),2)

We also need to pad the DDD with zeroes – which I’ll do by putting three zeroes in front of the number and getting the three rightmost characters.

SELECT RIGHT(‘000’ + CAST(DATEPART(dy, @date) AS varchar(3)),3)

Concatenating the YY and the DDD, we now have a TO_JULIAN function.

SELECT RIGHT(CAST(YEAR(@date) AS CHAR(4)),2) + RIGHT(‘000’ + CAST(DATEPART(dy, @date) AS varchar(3)),3)

Converting back again isn’t too hard – it’s just a matter of pulling the numbers out of the 5-character string. I’m going to assume we have a char(5) called @julian.

We need to split the string up first.

SELECT LEFT(@julian,2), RIGHT(@julian,3)

The first bit becomes the year easily enough

Convert Julian Date To Calendar Date In Unix

SELECT CONVERT(datetime, LEFT(@julian,2) + ‘0101’, 112)

The second half can be cast to a number, and then added back (subtracting one to get the maths right) using DATEADD.

SELECT DATEADD(day, CAST(RIGHT(@julian,3) AS int) – 1, CONVERT(datetime, LEFT(@julian,2) + ‘0101’, 112))

So now we have a FROM_JULIAN function:

Bash Script Convert Julian Date To A Calendar Date Today

SELECT DATEADD(day, CAST(RIGHT(@julian,3) AS int) – 1, CONVERT(datetime, LEFT(@julian,2) + ‘0101’, 112))

Bash Script Convert Julian Date To A Calendar Date

Easy stuff really, just a matter of thinking about what we mean by a particular format.