Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Converting Todays Date to Julien date.

Posted on 2004-09-04
15
Medium Priority
?
7,611 Views
Last Modified: 2012-08-13
I have a field in my table that is called OrderNo.  This order number is based on todays date.  Only the user has to look at a table to figure out what todays date is in Julien and thn they add a sequential number to the end.  Like if today was Jan 1st and this was the first record for the day the Order no. would be 001-001  and if it was the second record of the day then it would be 001-002 and so on until the next day then it would be 002-001.  Make sense?

Is there any VB code that could do this.  I am using Access 2003.

Thanks
John
0
Comment
Question by:John Sheehy
  • 7
  • 5
  • 2
  • +1
15 Comments
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 1600 total points
ID: 11982246
I have no idea what a Julien date is - do you mean a Julian date?

As for generating the order number, you can use the function I posted here to do it:
http://www.experts-exchange.com/Databases/MS_Access/Q_20525867.html

You have to work out the first part (the part based on the date).
0
 
LVL 12

Assisted Solution

by:fulscher
fulscher earned 400 total points
ID: 11982315
From your example, I assume that with "Julien date", you mean the number of the current day in the year. To find this date, you can use the DateDiff function as follows:

DateDiff("d", "01-01-2004", Date) + 1

to create the format required, you can use

format(DateDiff("d", "01-09-2004", Date) + 1, "000")

To find the correct record number, you have to check whether there are already records in the table for this date and you have to find the higest record number already used. As Shane has pointed out, he has a nice description of how this can be done in his article.

Hope this helps
Jan

Btw: Juilan dates: From http://aa.usno.navy.mil/data/docs/JulianDate.html:

"Julian dates (abbreviated JD) are simply a continuous count of days and fractions since noon Universal Time on January 1, 4713 BCE (on the Julian calendar). Almost 2.5 million days have transpired since this date. Julian dates are widely used as time variables within astronomical software. Typically, a 64-bit floating point (double precision) variable can represent an epoch expressed as a Julian date to about 1 millisecond precision. Note that the time scale that is the basis for Julian dates is Universal Time, and that 0h UT corresponds to a Julian date fraction of 0.5. "
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11982328
I'd add that if you want to find the current day of the year, you can just use:
DatePart("y",Date())

i..e.:
Format(DatePart("y",Date()),"000")

So you could call my function with:
CreateAutoNumber(Format(DatePart("y",Date()),"000") & "-",3)

Thanks for clarifying the Julian date thing Jan - I know what a Julian date is but I couldn't for the life of me work out why you'd want to number your invoices by counting the days from 4713BCE :-)
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 11982357
check this link if it would help in what you are trying to do

How to Convert Julian Days to Dates in Access and Back

http://support.microsoft.com/?kbid=209922
0
 
LVL 12

Expert Comment

by:fulscher
ID: 11982367
Just for clarification: If your reference date (i.e., the date when you start counting) is NOT in the current year, but in the last year, you should use the DateDiff function. If your reference is always the current year, you can use DatePart (which might be even a bit faster).

Things to watch:
- Users enters data in 2004-01-02, but the data concerns a business activity of 2003-12-31; how do you handle this?

- How do you handle multiple years of data? The keys will be the same...

Shane: Good idea, thanks.
0
 

Author Comment

by:John Sheehy
ID: 11982482
Shane,

I need a bit more help with undertsanding this:

Set rst = CurrentDb.OpenRecordset("SELECT Max([AccountNumber]) As MaxAccountNumberFROM tblCustomers WHERE [AccountNumber] Like " & Chr(34) & strPrefix & "*" & Chr(34))
If IsNull(rst!MaxAccountNumber) Then
   strAutonumber = strPrefix & Format(1,String(lngDigits,"0"))
Else
   strTemp = Mid$(rst!MaxAccountNumber
,Len(strPrefix)+1)


I understand the you are Selecting the MAX number from the field AccountNumber in the Table tblCustomer Where [AccountNumber] is like ????

But what is :
" & Chr(34) & strPrefix & "*" & Chr(34))

If it helps my table is tblAwards and the field is OrderNumber.
Sorry for the inconvenience in having to explain this to me.  I just need lame man terms.

Thanks
John


0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11982491
No problems John. The bit that you're referring to selects all records where the first part of the field is the same as the string that has been passed. If I can give an example, if you want to create a number starting 002-, you first have to check how many records already start with 002-, so you can determine what the following 3 digits should be.

You need to change the Set rst line to reflect your own field names, i.e.:
Set rst = CurrentDb.OpenRecordset("SELECT Max([OrderNumber]) As MaxAccountNumberFROM tblAwards WHERE [OrderNumber] Like " & Chr(34) & strPrefix & "*" & Chr(34))

I've left the MaxAccountNumber alias in as the rest of the code uses that.
0
 

Author Comment

by:John Sheehy
ID: 11982517
I liked your explanation.

=CreateAutoNumber(Format(DatePart("y",Date()),"000") & "-",3)

So I could place the above statment on the propertied sheet as the default for the filed Order Number

Right ?

John
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11982548
No, you wouldn't set it as a default value - you actually need to call the function in the BeforeUpdate event of the form. One of the things it does is to immediately save the record, in case someone else starts typing in a new record before you finish yours, to ensure that they get the right number.
0
 

Author Comment

by:John Sheehy
ID: 11982590
I do it on the beforeUpdate event of the form or the Field OrderNumber.  How does it know to update the field Order number?

John
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11982595
Sorry, I wasn't clear - you need to do it in the BeforeUpdate event of the *form* rather than the control. The function will run as soon as you start typing in some data in your form (that's when the form's BeforeUpdate event fires).
0
 

Author Comment

by:John Sheehy
ID: 11982602
But what tells it to store the data in the field OrderNumber?
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11982609
Basically, in the form's BeforeInsert (sorry, it needs to be the BeforeInsert, not the BeforeUpdate) event, you have a line of code like this:
Me!txtOrderNumber=CreateAutonumber(Format(DatePart("y",Date()),"000") & "-",3)

txtOrderNumber is the name of the text box which is bound to the OrderNumber field.
0
 

Author Comment

by:John Sheehy
ID: 11982624
You know you said that in the link above.  Sorry for being a pest about it.

But the code worked Great for me.  I am positive the 100 + people that use this will appreciate the time you and everyone else has put into this problem for me.

As I would love to give the points to everyone else here I am opted to split them with Shane and Jan.  Jan supplied the Date format that helped Shane out while helping me out.

Thanks to everyone here

John
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11982633
No problem John, glad I could help!
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

877 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