Date Formating

C

cmdolcet69

How can i format a Julian day and only the single digit in the year.

I only wnat the julian day and the last digit of the year (7)

For example the code below i thought would do this however i get
errors:

strBarcode = strBarcode & Format(CStr(DateDiff("d",
DateSerial(Year(Date), 1, 1), Date) + 1), "#000")
strbarcode = strbarcode & Right(CStr(Year(Of Date)()), 2)
 
S

ShaneO

cmdolcet69 said:
How can i format a Julian day and only the single digit in the year.

I only wnat the julian day and the last digit of the year (7)

For example the code below i thought would do this however i get
errors:

strBarcode = strBarcode & Format(CStr(DateDiff("d",
DateSerial(Year(Date), 1, 1), Date) + 1), "#000")
strbarcode = strbarcode & Right(CStr(Year(Of Date)()), 2)

If I understand you correctly, then the following will provide what
you're looking for -

Dim strBarcode As String = Format(Now, "dy")

or

Dim strBarcode As String = String.Format("{0:dy}", Now)


ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
C

cmdolcet69

If I understand you correctly, then the following will provide what
you're looking for -

Dim strBarcode As String = Format(Now, "dy")

or

Dim strBarcode As String = String.Format("{0:dy}", Now)

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.

I believe this is correct it printed out the 7 correct however i need
the 14(day in a julian date form. Can this be done?
 
S

ShaneO

cmdolcet69 said:
I believe this is correct it printed out the 7 correct however i need
the 14(day in a julian date form. Can this be done?


In the true definition of Julian Date, it is the number of days that
have elapsed since January the 1st, 4713 BC. Are you sure you want to
obtain this value? If you're generating your own unique naming
standard, why not choose something a little less painful?

For example, when I want a naming convention that provides a unique
name/number for a file, while at the same time still providing ease of
sorting, I use -

"yyyyMMdd" which would provide 20071214 (or 20071215 where I am right now).

If you insist on a Julian Date, then I will have a look at some code for
you.


ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
S

Stephany Young

Try:

strBarcode &= String.Format("{0:000}{1}", myDate.Date.Subtract(New
DateTime(myDate.Year, 1, 1)).TotalDays + 1,
myDate.Year.ToString.Substring(3))

where myDate is the date of interest as type DateTime
 
S

ShaneO

After re-reading your post, I understand you want the day of the year as
a number. I have come-up with the following -

Dim strBarcode As String _
= (DateDiff("d", CDate("01/01/" _
+ Format(Year(Now), "0000")) _
, Now) + 1) _
.ToString.PadLeft(3, "0"c) _
& Now.Year.ToString.Substring(3)

I hope this helps.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

format 1 digit year 1
Three Digit Julian Date 4
Excel Vba to change displayed year automatically. 14
Date Subtraction/Formatting Issues 4
Julian Date Question (Another) 4
Date Of Year 1
Code Optimization 0
Return a 3 digit number 2

Top