Julian dates (1 Viewer)

QMDirk

Member
Local time
Today, 15:19
Joined
Nov 16, 2019
Messages
52
I was using the code below to display a text string on a form. It worked fine until the new year, now instead of getting the day of the year to appear in Julian format (today is "005") I'm getting "5Su".


example: on the form, txtJulDate displays"540105Su20". Should display "5401000520".



Any suggestions? Thanks.



Private Sub Form_Load()
Dim PN As String 'Plant Number "5401"
Dim YR As String 'last digit of the year
Dim JD As String 'julian day section
Dim DC As String ' single digit to represent the decade
Dim TD As String 'today's date and time
PN = "5401"
YR = "0"
JD = Left(Format(Now, "Yddd"), 3) 'used Left....3, because I'm not displaying the ''y" part
DC = "2"

On Error Resume Next 'on the form, "txtJulDate" is an UNBOUND textbox
'that displays the string, read-only
Me.txtJulDate = PN & YR + JD & DC & "0"
Me.txt270 = Date + 270
Me.txt360 = Date + 360
Me.txt480 = Date + 480
Me.txt560 = Date + 560
Me.txt720 = Date + 720
Me.txt730 = Date + 730
End Sub
 

isladogs

MVP / VIP
Local time
Today, 23:19
Joined
Jan 14, 2017
Messages
18,239
Your formatting is incorrect.
From the immediate window

Code:
?format(Now,"yddd")
5Sun
?Left(format(Now,"yddd"),3)
5Su

Counterintuitively 'y' is used for the Julian date so
Code:
?format(Date,"y")
5

?format(Date,"yyyyy")
20205

?Mid(format(Date,"yyyyy"),4)
05

If you want 005, you need to do a bit more work
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 18:19
Joined
May 21, 2018
Messages
8,535
JD = Format(DatePart("y", Date), "000")
 

Users who are viewing this thread

Top Bottom