Solved

Convert 7 Digit Julian Date To A Calendar Date MMDDYYYY in a Access Query

Posted on 2014-03-24
14
2,903 Views
Last Modified: 2014-03-25
I have a 7 digit number stored in a text field that is actually a Julian Date that needs to be converted to a calendar date, format mmddyyyy in a Microsoft Access Query.
0
Comment
Question by:rjordanbots
  • 4
  • 4
  • 3
  • +1
14 Comments
 
LVL 3

Expert Comment

by:englanddg
ID: 39952256
Try using DateSerial(Left([FieldName],2),1,Right([FieldName],3))
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39952273
are you sure that what you have are Julian dates?
post sample values.
you can use this code for conversion

Function CJulian2Date (JulDay As Integer, Optional YYYY)
    If IsMissing(YYYY) Then YYYY = Year(Date)
    If Not IsNumeric(YYYY) Or YYYY \ 1 <> YYYY Or YYYY < 100 Or YYYY _
      > 9999 Then Exit Function
    If JulDay > 0 And JulDay < 366 Or JulDay = 366 And _
      YYYY Mod 4 = 0 And YYYY Mod 100 <> 0 Or YYYY Mod 400 = 0 Then _
        CJulian2Date = Format(DateSerial(YYYY, 1, JulDay), "m/d/yyyy")
End Function


'    JulDay: The ordinal day of a year. Between 1 and 365 for all
'            years, or between 1 and 366 for leap years.
'
'    YYYY: A three or four digit integer for a year that is within the
'          range of valid Microsoft Access dates. If YYYY is omitted,
'          then YYYY is assumed to be the year of the current system
'          date.
'

codes taken from this link
0
 
LVL 12

Expert Comment

by:KRUNAL TAILOR
ID: 39952282
Hi rjordanbots,

select DateSerial(Left([JulianField],2),1,Right([JulianField],3))
from table
 
You can also write a function in your database. like this_

Function JulianToDate(JulianDate As String) As Date

  Dim astrDatePart() As String
  
  astrDatePart = Split(JulianDate, ".")
  
  JulianToDate = DateSerial(CInt(astrDatePart(0)), 1, CInt(astrDatePart(1)))

End Function

Open in new window



Then in the query we can use the function directly.
 
select JulianToDate(table.[Myfield])
from table

More Refrence here: http://support.microsoft.com/kb/162745

Thanks & Regards,
Krunal T. Tailor
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

Author Comment

by:rjordanbots
ID: 39952285
Can you tell me what Julian Date 2032306 should convert to ?

I believe it should be 11012032
0
 
LVL 12

Expert Comment

by:KRUNAL TAILOR
ID: 39952294
Hi rjordanbots,

Please check over here http://aa.usno.navy.mil/data/docs/JulianDate.php

There are so many online converter available like_
1) http://www.onlineconversion.com/julian_date.htm
2) http://www.aavso.org/jd-calculator

Thanks & Regards,
Krunal T. Tailor
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39952295
if that (2032306) is a julian date the conversion is 7/22/2306 using the function above
0
 

Author Comment

by:rjordanbots
ID: 39952307
This number is coming off of a Ibm I-Series MainFrame. I believe the first four digits is the year then the last three is the number of days. Can this be converted in Access to an actual date ?
0
 
LVL 3

Expert Comment

by:englanddg
ID: 39952308
If you have Julien dates...@Krunal has your solution.

That code is solid.
0
 
LVL 3

Expert Comment

by:englanddg
ID: 39952310
Oh, data dump?

Yes.  Use the right and left functions.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39952315
believe the first four digits is the year then the last three is the number of days. Can this be converted in Access to an actual date ? Yes

using the function

CJulian2Date(306,2032)

the value will be  11/1/2032
0
 
LVL 12

Expert Comment

by:KRUNAL TAILOR
ID: 39952322
Yes,  Rey Obrero is correct.

Please check here more ref: http://support.microsoft.com/kb/162745
Something like this:

CJulian2Date(32, 1996)
Note that your system's date format for 2/1/96 is returned. If your system's date is in 1996 then CJulian2Date(32) will also return 2/1/96.

Thanks & Regards,
Krunal T. Tailor
0
 

Author Comment

by:rjordanbots
ID: 39952326
The first four digits is the year 2032, the last 3 are the # of days, which is 306, need to convert the last 3 digits, which appears to be the julian day to an actual date

The date should read 11012032
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39952372
<The date should read 11012032 >

in the function above

change this line

        CJulian2Date = Format(DateSerial(YYYY, 1, JulDay), "m/d/yyyy")

with

        CJulian2Date = Format(DateSerial(YYYY, 1, JulDay), "mmddyyyy")
0
 

Author Closing Comment

by:rjordanbots
ID: 39954124
Thanks for your help, all of this information was very helpful.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question