Solved

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

Posted on 2014-03-24
14
2,740 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 119

Expert Comment

by:Rey Obrero
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
 

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 119

Expert Comment

by:Rey Obrero
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 119

Expert Comment

by:Rey Obrero
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 119

Accepted Solution

by:
Rey Obrero 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I recently went through setting up a JasperReports Server using the AWS EC2 instance, and this article will cover some basic administration tasks I had to perform.
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now