Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to save a date as a number? 2

Status
Not open for further replies.

Andviv

Programmer
Aug 6, 2001
29
US
I know that one can represent a date as a number, but I don't remember how this is done.
Can somebody help me to find this?

I need this because I need to represent a date in a barcode generated by VB and I think it is better to use a number than to use a date in format YYYYMMDD for this.

Thanks in advance,
 
Hi,

Change it from a Date variable to something else, eg:

a& = CLng(Now)
returns something like
36546

a# = CDbl(Now)
returns something like
36546.0394573584

- Andy.
 
Yes, that is it.

How can I make it?
 
Try CDbl:

?CDbl(#12/20/63 3:00 PM#)
23365.625
?CDate(23365.625)
12/20/1963 3:00:00 PM


 
Thank you guys!!!!

that is exactly what I was looking for.
 
I have used this code in the past. Credit is not mine.
Public Function JulianDate(ByVal datDate As Date) As Double
Dim GGG
Dim DD, MM, YY
Dim S, A
Dim JD, J1

MM = Month(datDate)
DD = Day(datDate)
YY = Year(datDate)
GGG = 1

If (YY <= 1585) Then
GGG = 0
End If

JD = -1 * Int(7 * (Int((MM + 9) / 12) + YY) / 4)
S = 1

If ((MM - 9) < 0) Then
S = -1
End If

A = Abs(MM - 9)
J1 = Int(YY + S * Int(A / 7))
J1 = -1 * Int((Int(J1 / 100) + 1) * 3 / 4)
JD = JD + Int(275 * MM / 9) + DD + (GGG * J1)
JD = JD + 1721027 + 2 * GGG + 367 * YY

If ((DD = 0) And (MM = 0) And (YY = 0)) Then
MsgBox &quot;Please enter a meaningful date!&quot;
Else
JulianDate = JD
End If

End Function
 
Andviv,
Just so you know the CDBL() does not give you a Julian date(if thats what you were looking for)
 
About a year or so ago we had some threads in here on Julian dates. Try doing a key word search if Julians are what you are looking for.
 
To woyler,

There is nothing like a standard for a julian day. There are also such called 'Modified Julian Days', which either use a different start of the day (midnight or midday), or they are using different epochs. But they have all one thing in common, and that is, that they represent a number of days passed since a specified start epoch date (usually it is 1. Jan. 4712 B.C. 12:00). The fraction of the number represent the time of the day (e.g. 0.5 = 12:00 or 0.75 = 18:00). VB uses internally a double to store dates in the above manner. However VB uses a different startdate, which is the 30. Dec. 1899 0:00 o'clock (negative numbers represent dates before, and positive numbers represent dates after).

By OpenWater

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top