Solved

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

Posted on 2014-03-24
14
3,261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

617 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