Date Formating

  • Thread starter Thread starter cmdolcet69
  • Start date Start date
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)
 
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.
 
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?
 
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.
 
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
 
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.
 
Back
Top