TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > VB.NET

Notices

Date Formating

VB.NET


Reply
 
Thread Tools Display Modes
Old 15-12-2007, 03:29 AM   #1
cmdolcet69
Guest
 
Posts: n/a
Date Formating

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)
  Reply With Quote
Old 15-12-2007, 03:29 AM   #2
ShaneO
Guest
 
Posts: n/a
Re: Date Formating

cmdolcet69 wrote:
> 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.
  Reply With Quote
Old 15-12-2007, 03:29 AM   #3
cmdolcet69
Guest
 
Posts: n/a
Re: Date Formating

On Dec 14, 4:38 pm, ShaneO <.au> wrote:
> cmdolcet69 wrote:
> > 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.


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?
  Reply With Quote
Old 15-12-2007, 05:12 AM   #4
ShaneO
Guest
 
Posts: n/a
Re: Date Formating

cmdolcet69 wrote:
>
> 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.
  Reply With Quote
Old 15-12-2007, 05:12 AM   #5
Stephany Young
Guest
 
Posts: n/a
Re: Date Formating

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


"cmdolcet69" <> wrote in message
news:...
> On Dec 14, 4:38 pm, ShaneO <.au> wrote:
>> cmdolcet69 wrote:
>> > 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.

>
> 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?


  Reply With Quote
Old 15-12-2007, 05:12 AM   #6
ShaneO
Guest
 
Posts: n/a
Re: Date Formating

ShaneO wrote:
> cmdolcet69 wrote:
>>
>> 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?

>
>

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.
  Reply With Quote
Reply

Thread Tools
Display Modes



< Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 04:07 AM.


vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2009, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional