473,396 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Converting Gregorian date to Julian date (Access 2003)

I know that there is a thread about this, but I was unable to add to it; I just joined. The problem is that I do not want to change the date format for the entire database output, merely for a header on a report and for a field on that report.

I thought that I could just go into the expression builder and paste one of the codes that were posted in the thread about this conversion-you'll know that did not work.

So, I went to the new module and tried to enter the following information into the Immediate Window, but it did not work.

? Right(Year(#1/20/2003#),1) &
Format(DateDiff("d",#1/1/2003#,#1/20/2003#)+1,"000")
3020

I followed the direction to enable the 'Require Variable Declaration' in the 'Tools' menu of the Visual Basic Editor and then copied the following into the 'Procedure Window':

FUNCTION: CDate2Julian()

PURPOSE: Convert a date to a Julian day. The function works with dates based on the Gregorian (modern) calendar.

ARGUMENTS:
MyDate: A valid Microsoft Access date.

RETURNS: A three digit Julian day as a string.

End function

However, the entire type in the procedure window changes to red font color and it is invalid in the immediate window as well...

Bottom line, can one of you programmers confirm that it is not known how to get the Julian date from a 'Expression' in a field of a query that this new Report will draw data from?

Thanks much, Paul Davis
Dec 8 '06 #1

✓ answered by mattmorris0531

An extremely easy way to do this is
Expand|Select|Wrap|Line Numbers
  1. Format(Date, "y")

14 16835
cyberdwarf
218 Expert 100+
Hi

I worked on this a some time ago, but haven't looked at it in a while
Expand|Select|Wrap|Line Numbers
  1. Function julDay(theDate) As String 
  2. ' Param: date with year 
  3. ' Returns: Julian date version of passed date
  4.  
  5. Function julDay(theDate) As String 
  6. ' Arg: A date with year 
  7. ' Returns: Julian date version of passed date
  8. Dim monthLen() As Integer 
  9. Dim myMonth As Integer 
  10. Dim i                  As Integer 
  11. Dim numDays As Integer 
  12.  
  13. If Not IsDate(theDate) Then 
  14.     MsgBox "Invalid Date" 
  15.     julDay = "[ERROR]" 
  16. Else 
  17.     ReDim monthLen(1) 
  18.     monthLen(1) = 31 
  19.  
  20.     ReDim Preserve monthLen(2) 
  21.     If Year(theDate) Mod 4 = 0 Then 
  22.      monthLen(2) = 29 
  23.     Else 
  24.      monthLen(2) = 28 
  25.     End If 
  26.  
  27.     ReDim Preserve monthLen(3) 
  28.     monthLen(3) = 31 
  29.     ReDim Preserve monthLen(4) 
  30.     monthLen(4) = 30 
  31.     ReDim Preserve monthLen(5) 
  32.     monthLen(5) = 31 
  33.     ReDim Preserve monthLen(6) 
  34.     monthLen(6) = 30 
  35.     ReDim Preserve monthLen(7) 
  36.     monthLen(7) = 31 
  37.     ReDim Preserve monthLen(8) 
  38.     monthLen(8) = 31 
  39.     ReDim Preserve monthLen(9) 
  40.     monthLen(9) = 30 
  41.     ReDim Preserve monthLen(10) 
  42.     monthLen(10) = 31 
  43.     ReDim Preserve monthLen(11) 
  44.     monthLen(11) = 30 
  45.     myMonth = Month(theDate) 
  46.     For i = 1 To myMonth - 1 
  47.         numDays = numDays + monthLen(i) 
  48.     Next i 
  49.  
  50.     numDays = numDays + Val(Format$(theDate, "dd")) 
  51.     julDay = Format$(theDate, "yy") & Format$(numDays, "000") 
  52. End If 
  53. End Function 
  54.  
Credit to Pete Cresswell

hth

Steve
Dec 8 '06 #2
cyberdwarf
218 Expert 100+
Paul


A couple of other suggestions:-
Expand|Select|Wrap|Line Numbers
  1. datepart("y", now) + (year(now) - 1900) * 1000 
Or:-

Expand|Select|Wrap|Line Numbers
  1. juliandate = Right(DatePart("yyyy",[greg_date]),2) & 
  2. Format(DateDiff("d",CDate("01" & "/" & "01" & " /" & 
  3. DatePart("yyyy",[greg_date])),[greg_date])+1,"000") 
No guarantees, tho'

HTH

Steve
Dec 8 '06 #3
NeoPa
32,556 Expert Mod 16PB
I'm not sure what the Julian version is exactly, but the day in year number can be got by :
Expand|Select|Wrap|Line Numbers
  1. datVar+1-cdate("1/1/" & year(datVar))
where datVar is the date variable.
Dec 8 '06 #4
Hey Gang,

I know that one was a bear. Thank you all for the assistance, though I was unable to make it work. No worries, it was appreciated and I am sure it will help lay the foundational knowledge necessary to working with code in Access.

Have a good one, Paul
Dec 11 '06 #5
Killer42
8,435 Expert 8TB
I'm not sure what the Julian version is exactly, but the day in year number can be got by :
Expand|Select|Wrap|Line Numbers
  1. datVar+1-cdate("1/1/" & year(datVar))
where datVar is the date variable.
I realise this thread is long finished, but I have been looking into converting a date value to julian format today, and came across it while searching. After trying NeoPa's suggestion (which works, of course) I found that you can get the same value from DatePart - the "y" parameter gives you "Day of year".

So I wrote the following routine in VB6, which for 15 Feb 2007, returns "200746". Should also work in VBA.
Expand|Select|Wrap|Line Numbers
  1. Public Function Julian(ByVal datVal As Date) As String
  2.   Julian = DatePart("yyyy", datVal) & DatePart("y", datVal)
  3.   ' Could also use this...
  4.   ' Julian = Year(datVal) & DatePart("y", datVal)
  5. End Function
I suppose it's a bit of an open question as to which function is the more efficient, DatePart or CDate. Probably not a huge difference, in any case.
Feb 15 '07 #6
NeoPa
32,556 Expert Mod 16PB
It seems to me that DatePart() would be preferable.
It's what I would have chosen if I'd thought about it first ;)
Feb 15 '07 #7
Killer42
8,435 Expert 8TB
How would one go about converting the other way? That is, Julian to Gregorian? I just realised I have an application which will need to do this shortly.

Obviously I'll find some way to do it, but it's likely to be rather kludgy (like counting through Julian dates until one matches, or something). I'd like to find a nice, clean method.
Feb 15 '07 #8
NeoPa
32,556 Expert Mod 16PB
Use DateAdd("d",Julian bit,#31 Dec Year-1#)
Feb 15 '07 #9
Killer42
8,435 Expert 8TB
Use DateAdd("d",Julian bit,#31 Dec Year-1#)
I like it! :)

Thanks.
Feb 15 '07 #10
NeoPa
32,556 Expert Mod 16PB
Thank you Killer.
It's always nice to get appreciation from a connoisseur :)
Feb 15 '07 #11
shiznaw
29
I'm not sure what the Julian version is exactly, but the day in year number can be got by :
Expand|Select|Wrap|Line Numbers
  1. datVar+1-cdate("1/1/" & year(datVar))
where datVar is the date variable.
what you just posted is, in actuality, the Julian Date. And had saved the rest of us, approximately 52 lines of coding otherwise.

Thank you, Neopa. No, seriously...Thanxs

Shiznaw
Univ of Utah
Jun 26 '07 #12
NeoPa
32,556 Expert Mod 16PB
Not a problem Shiznaw.
I enjoy seeing shortcuts in code. Sometimes I have to forswear them because they make maintenance too complex, but I feel better if I see them anyway at least ;)
Jun 28 '07 #13
An extremely easy way to do this is
Expand|Select|Wrap|Line Numbers
  1. Format(Date, "y")
May 21 '10 #14
NeoPa
32,556 Expert Mod 16PB
I think you're right Matt. It seems we all overlooked this. I must admit I rarely ever use Julian dates myself.
May 23 '10 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: goochey | last post by:
I'm trying to convert a Julian Date (Format "4365") into an actual calendar date in Visual Basic, can anyone help me out with this.
6
by: Jim Davis | last post by:
Before I reinvent the wheel I thought I'd ask: anybody got a code snippet that will convert the common ISO8601 date formats to a JS date? By "common" I mean at the least ones described in this...
3
by: Chris Davoli | last post by:
Is there a class that converts from Gregorian date to TRUE Julian Date in ..NET? Any VB.NET examples available? ie; The Julian date is calculated by the number of days since January 1, 4713 BC....
1
by: Sam | last post by:
How do I convert Julian Date to Calendar Date in ASP.Net 1.1 based on following guideline found at Internet? To convert Julian date to Gregorian date: double JD = 2299160.5; double Z =...
1
by: mbsevans | last post by:
New Access user here. I have a simple datebase containing employee information. I have 3 differents dates which reflect the DUE date for a qualification that each employee needs in order to continue...
1
by: heckstein | last post by:
I am running a query in Access 2003 to pull training courses with a start date that falls within a specified date span such 2/1/07 to 2/28/07. I was using this code - (( I.STARTDATE) Between...
5
by: amanda27 | last post by:
I have a database that we use in our department for the status of our projects. In the form when you pick a project from the dropdown list I have a subform that pulls the data entered for the...
1
by: saddist | last post by:
Hello, In access 2003 I have date format yyyy/mm/dd, but I want it to be dd/mm/yyyy. I tried to enter dd"/"mm"/"yyyy and dd/mm/yyyy in format property, but it changes automaticly to dd/mm"/yyyy"....
9
chandru8
by: chandru8 | last post by:
hi to all iam using vb6.0 can any one correct me the query which below mentioned is correct strSql = "Insert into table1 values (#" & Date & "# ,'2')" Set rs = objCon.Execute(strSql) or
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.