473,513 Members | 2,537 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help Convert Julian Date to regular date

45 New Member
I am new to access and I am learning as I go along; I am attempting to convert Julian dates to regular dates "MM-DD-YY"; I have tried the code below in the Query screen under criteria.

Expand|Select|Wrap|Line Numbers
  1. CDate(Format(((DateValue("01/01/"+LTrim(Str(1900+Int([Your Field Name]/1000))))+[Your Field Name]-Int([Your Field
  2. Name]/1000)*1000))-1,"mm-dd-yy"))
Trouble is it's not bringing up any result; the database field it's been applied to is blank now?

I am not even sure if I am going about it the right way
Aug 13 '09 #1
15 16095
Delerna
1,134 Recognized Expert Top Contributor
There may be a function that will convert it for you but I don't know it.

So
The format that I am familiar with for Julian date is 4 digits the first 3 is the day number of the year and the last is the last digit in the year. Therefore you must know the decade that the date falls within.

So to convert it yourself you need to calculate the year
I will assume the date is in the decade 01/01/2000 - 31/12/2009
which means the decade start year is 2000
I also assume the Julian date is of type string

so the year is
2000 + cint(right(JulianDte,1))
and the date is 01/01/CalculatedYear + (The3DigitJulianDay-1)


The complete statement would be something like

cdate("01/01/" & cstr(2000 + cint(right(JulianDte,1)) )) + cint(left(JulianDte,3)-1)

Where JulianDate is the field name of the Julian Date field
and of course you can add the date format bit in if you want

I hope I got enough brackets there and I hope it helps
Aug 13 '09 #2
OldBirdman
675 Contributor
Widipedia informs that Julian Date, as used in Computer Science is Ordinal Date, a date as yyyy-ddd where ddd is the day number for the year, with values from 1 to 365 (366 if leap year).

After verifying that yyyy is a numeric value (probably between 1900 and Now() ) and that ddd is numeric and 1-366, then the date is
Expand|Select|Wrap|Line Numbers
  1. dteYourDateVariable = DateAdd("d", Mid(strJulianDate, 6), "12/31/" & Left(strJulianDate, 4) - 1)
Aug 13 '09 #3
toadmaster
45 New Member
Thank you Delerna and OldBirdMan for the prompt reply.

The following are samples of the dates I am attempting to convert

81105
120505
102901
71894

The field name is [TOBIDE]; the Data Type is "Number" and the field size is set to "Decimal" (I have tried to change the data type to Date/Time - Keep getting error messages saying it's run of disk space) everytime I run the query below

CDate(Format(((DateValue("01/01/"+LTrim(Str(1900+Int([TOBIDE]/1000))))+[TOBIDE]-Int([TOBIDE]/1000)*1000))-1,"mm-dd-yy"))

It just falls over does not bring any results in the table; but once I take the query out from the Criteria it returns the julian dates listed above???

I need to get these dates into "MM-DD-YY"
Aug 13 '09 #4
OldBirdman
675 Contributor
These are neither true Julian Dates, where today would be 2455057, or Ordinal Dates, where today would be 2009-226. They are not as Delerna thought, days since the start of the decade. Subtracting 120505 from today's date gives a year of 1570, not a probable start date for any counting system.
The best guess is that these numbers are the date & time where the time is the last 3 digits. The remaining digits: 81, 120, 102, 71 would all then be number of days in year, but which year?

Rereading the original post, I am completely confused.
1) Where are these numbers? In a table, I assume because
The field name is [TOBIDE]; the Data Type is "Number" and the field size is set to "Decimal"
that field is a field in a table, and not a control on a form.

2)The criteria stated seems to be copied from an example without any adjustments for this project.
I have tried the code below in the Query screen under criteria.
CDate(Format(((DateValue("01/01/"+LTrim(Str(1900+Int([Your Field Name]/1000))))+[Your Field Name]-Int([Your Field
Name]/1000)*1000))-1,"mm-dd-yy"))
What is [Your Field Name] in this context?

3)A criteria is to test against a field. What is in the field being tested against. WHERE [Value]=7 tests the field "Value" against the number 7, but what is this criteria testing against.

4)
I am attempting to convert Julian dates to regular dates "MM-DD-YY";
and put the answer where?

5)
Trouble is it's not bringing up any result; the database field it's been applied to is blank now?
What is a database field? What & where is this 'blank'?

This question needs to be clarified before any real help can be given. Without information such as how to manually interpret the numbers given as dates, I don't see an answer. As far as the query goes, more explanation is needed.
Aug 13 '09 #5
toadmaster
45 New Member
I appreciate your help OldBirdman; this is the situation:

These numbers are being displayed in a table called MKF22(table name) under TOBIDE(field name)

81105
120505
102901
71894

I am trying to extract the date and time from the numbers above and to display them as "MM/DD/YY" in the TOBIDE(field name) under the (MKF22) table instead of the current form that is being displayed.

Eg:

Currently 81105 is what is being displayed would like it to show 08/11/2005 (if that is the correct date format)? I hope I am making sense????????? As I said I am very new to access.

Thank you!!!!!!!!!!!
Aug 13 '09 #6
Delerna
1,134 Recognized Expert Top Contributor
So those are simply the date with the /'s removed in
either "mmddyy" or "mddyy" format


81105=08/11/05
120505=12/05/05
101201=10/29/01
71894=07/18/94

If that is the case then something like this might work
Expand|Select|Wrap|Line Numbers
  1. cdate(
  2.    iif(len(TOBIDE)=5,left(cstr(TOBIDE),1),left(cstr(TOBIDE),2)
  3.    & "/" & 
  4.    left(right(cstr(TOBIDE),4),2) 
  5.    & "/" & 
  6.    right(cstr(TOBIDE),2)
  7. )
  8.  
Aug 13 '09 #7
Delerna
1,134 Recognized Expert Top Contributor
Incidentally, I thought I would try plugging one of the values into your formula
and calculate it out by hand to try and see why you were getting the error.

I didn't discover the reason for the error but the result is interesting
Expand|Select|Wrap|Line Numbers
  1. CDate(Format(((DateValue("01/01/"+LTrim(Str(1900+Int([TOBIDE]/1000))))+[TOBIDE]-Int([TOBIDE]/1000)*1000))-1,"mm-dd-yy"))
  2. CDate(Format(((DateValue("01/01/"+LTrim(Str(1900+Int( 120505/ 1000))))+ 120505 -Int( 120505 /1000)*1000))-1,"mm-dd-yy"))
  3. CDate(Format(((DateValue("01/01/"+LTrim(Str(1900+        120       )))+ 120505 -        120       *1000))-1,"mm-dd-yy"))
  4. CDate(Format(((DateValue("01/01/"+LTrim(Str(        2020           )))+ 120505 -           120000      ))-1,"mm-dd-yy"))
  5. CDate(Format(((DateValue("01/01/"+          "2020"                   )+            505                 ))-1,"mm-dd-yy"))
  6. CDate(Format(((DateValue("01/01/2020"                                )+            505                 ))-1,"mm-dd-yy"))
  7. CDate(Format(( 05/20/2021)-1                                                                               ,"mm-dd-yy"))
  8. CDate(Format(05/19/2021,"mm-dd-yy")
  9.  
Assuming I havent made a mistake, the answer 05/19/2021
is nothing like the result 12/05/05
you are after.

When I have difficulty with large unwieldly formulas I sometimes do this to help me spot why its not working.

More usually I tend to build the formula up one piece at a time as separate fields before combining them into the final formula. That way I can see which part of the formula is going wrong as I write it.


Going from memory here, most of my queries are written on SQL server these days,
but I don't think you can do this
"01/01/" + "2020" in access can you?
Dosn't it have to be "01/01/" & "2020" ?
Aug 14 '09 #8
toadmaster
45 New Member
Delerna you are genius; expert doesn't even begin to describe your abilities.

Works like a charm; the thing is I could never figure out why I kept getting 05/19/2021
instead of 12/05/05.

I got those same results even with simple formating like

Expr1: Format:([TOBIDE], "mm/dd/yy")

Even though the date should already be in "mmddyy" format.

Thank you and OldBirdman!!!!!!!!!!! YOU BOTH ROCKKKKKKKKKKKKKKKKKK
Aug 14 '09 #9
Delerna
1,134 Recognized Expert Top Contributor
I can't get my head out the door now :)

Seriously though, every expert (whether they have that word against their name or not) in every topic here ....... You ROCKKKKKKKKK.
Aug 16 '09 #10
OldBirdman
675 Contributor
To simplify the issue, these numbers can be converted to Access dates by
Expand|Select|Wrap|Line Numbers
  1. CDate(Format(120505,"&&/&&/&&")) 
Aug 16 '09 #11
Delerna
1,134 Recognized Expert Top Contributor
That's much better than my clunky method
Aug 16 '09 #12
toadmaster
45 New Member
Quick question? I attempting to include an 'OR' condition to handle fields that are blank or have a '0' value.

I have tried both of the following statements and non of them seem to do it?

Eg 1 :
OR IIf(([TOBIDE])= "", [TOBIDE])

Eg 2:

OR IIf(Len([TOBIDE])= 1, [TOBIDE])

the entire statement in my query goes like this

cdate(
iif(len(TOBIDE)=5,left(cstr(TOBIDE),1),left(cstr(T OBIDE),2)
& "/" &
left(right(cstr(TOBIDE),4),2)
& "/" &
right(cstr(TOBIDE),2) OR IIf([TOBIDE]) = "",([TOBIDE])
)

The entire OR section is being ignored when I run the query...........
Aug 17 '09 #13
toadmaster
45 New Member
I have figured out a way to get the blank field to display "0" as against the following data 12:00:00 AM or 12/29/1899 which it was giving me earlier by using the following query(tips from Delerna)

IIf(Len([TOBIDE])=1,0)

but the problem right now is combining it with the previous IIf statement; I keep getting #Error or it totally ignores the query altogether???? Below is the query

cdate(
iif(len(TOBIDE)=5,left(cstr(TOBIDE),1),left(cstr(T OBIDE),2)
& "/" &
left(right(cstr(TOBIDE),4),2)
& "/" &
right(cstr(TOBIDE),2), IIf(Len([TOBIDE])=1,0))

I have tried using OR in there to handle the second IIf function and it does not work????????????? Any Suggestions????????????
Aug 17 '09 #14
Delerna
1,134 Recognized Expert Top Contributor
Blank fields can be handled with NZ.
In a query it is used something like this
Expand|Select|Wrap|Line Numbers
  1. SELECT NZ([TheField],TheValueToReturnIf[TheField]IsNull) as FieldName
  2.  

With the method I gave you, you would wrap my if in the false part of another if. (Its called a Nested IIF)

so
IIF(len(NZ(TOBIDE,0))=1,null,MyClunkyIIF)

You finish up with an iff within an iif like this
Expand|Select|Wrap|Line Numbers
  1. iif(len(NZ(TOBIDE,0))=1,null,
  2.    cdate
  3.    (   iif(len(TOBIDE)=5,left(cstr(TOBIDE),1),left(cstr(TOBIDE),2) 
  4.        & "/" &  
  5.        left(right(cstr(TOBIDE),4),2)  
  6.        & "/" &  
  7.        right(cstr(TOBIDE),2) 
  8.    ) 
  9. )
  10.  

HOWEVER
Using OldBirdman's much neater suggestion you could do something like this

Expand|Select|Wrap|Line Numbers
  1.  
  2. IIF(len(NZ(TOBIDE,0))=1,null,CDate(Format(TOBIDE,"&&/&&/&&")))
  3.  
  4.  
Aug 17 '09 #15
toadmaster
45 New Member
YOU Guys did it ones again; thank you so much. The more I discover the more interesting Access gets!!!!!!!!!!!!!!!! Awesome
Aug 18 '09 #16

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

Similar topics

6
2019
by: paulsmith5 | last post by:
Hi, I have the following regular expression to validate a date-time field in European or d/m/y h:m:s format. ^((((31\/(0?|1))|((29|30)\/(0?|1)))\/(1|\d)?\d{2})|(29\/0?2\/(((1|\d)?(0||)|((16||)00))))|(0?|1\d|2)\/((0?)|(1))\/((1|\d)?\d{2})) (20|21|22|23|?\d):?\d:?\d$ I wish to ammend it so that the time or h:m:s part is validated only if...
4
1484
by: Chris Kettenbach | last post by:
Does anyone know of a regualr expression to validate US and Canadian Postal Codes? I want to be able to accept ##### or #####-#### or Canadian A#A #A# that is alpha,number,alpha number,alpha,number. I am new to regular expressions. The US 5 digit part is easy, but I get stuck after that. var pattern = new RegExp(/\\d{5}/)
1
4857
by: Raja | last post by:
Hi Anyone has any idea of how to convert Julian Date (eg. 12744057862..) to a VB.NET date time. Thanks in advance.
1
4526
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 = Math.Floor(JD+0.5); double W = Math.Floor((Z - 1867216.25)/36524.25); double X = Math.Floor(W/4);
1
1950
by: Michael D. Reed | last post by:
I am using the help class to display a simple help file. I generated the help file using Word and saving it as a single page Web page (.mht extension). I show the help file with the following statement. Help.ShowHelp(Parent:=Me, url:=Me.HELP_URL_PRE & Me.myWorker.HelpFile) How do I get it to go away when the program exits? Now when I quit...
2
3554
by: No Spam | last post by:
Dear Access 2003 Users, I have been given an Excel 2003 spreadsheet with thousands of records, and I need to bring it into Access 2003. Does anyone know an Access formula that can convert these dates to "normal" dates? These are some examples of the dates that were sent to us: 738220000 629420000
4
4078
by: Bit byte | last post by:
How may I represent dates as Julian dates - I have seen code where julian dates are represented as longs, and other where they are represented as floats. Which is the correct representation? Anyone knows where I can obtain a routine for converting: 1). Dates to/from julian representations 2). Date/time values to/from Julian representations
2
3137
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button then the calender gone actually i want if i click outside off the calender then it should me removed ..How kan i do this ... Pls inform me as early...
1
9740
by: smdmca | last post by:
I have Julian date, I want to convert it into date. Is there any function in MySql to convert Julian date to date eg- Julian Date- 2455116 Date - Oct - 12, 2009
0
7270
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7565
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7128
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5103
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4759
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3255
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
473
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.