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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Julian date to string

Status
Not open for further replies.

kerrigirrl

Programmer
Mar 29, 2001
39
US
on my form i have 1 text field where the user enters the current date, ie 5/18/01. a second (locked) text field is bound to the 1st and formats the date to julian (01138). i need this 2nd date in a string format. when i code MyString = CStr(txtJulian), i get "5/18/01". i need "01138". Can anybody help me?

thanks in advance,
kerri
 
that's amazing. i've been trying everything i could think of. any chance you want to explain that? i'd like to be able to do it with mmddyy (no separaters) also.
 
The article explains it 100 times better than I could in this space. Make sure you check it out... :)

Joe Miller
joe.miller@flotech.net
 
CurDate = #5/18/01#

Format(CurDate, "yy") & Trim(Str(DateDiff("d", "1/1/" & Year(CurDate), CurDate)+ 1))


Not any real difference, but this may be easier to "de-Code".

Format(CurDate, "yy")

Format always returns a string. This returns the last two digits of the year. THE "01" at the beginning of your julian date.

Trim(Str(DateDiff("d", "1/1/" & Year(CurDate), CurDate)+ 1))

Worknig sort of, from the inside out.DateDiff returns a number. We'll get back yto date diff momentarily.

Because datediff returns a number, we need to get the string representation. Whhen you get the string of a number, it MAY have a leading space - which was 'reserved" for the sign however, if the sign was "+", it is 'assumed" and not shown, so the string has the space - but not the actual character. Trim removes the (possible) leading space.

Datediff is truly versitile, so I will not attempt to cover any more than is necessary to ubderstand this use.

DateDiff (as previously noted) always returns a number. In this useage, the number is the number of "d"ays between the two supplied dates.
"1/1/" & Year(CurDate), AND CurDate)+ 1

the first of these is just new years day of the year. the "1/1/" represents January (First Month) and 1 the first daay of the month, while Year(CurDate) is the year of the date being used. In the example, I just placed it in a variable "CurDate"

CurDate + 1 is just the date used in the example, while the + 1 is just the normal arith adjustment to include the end points in the difference calculation. The overall effect is to return the number of DAYS from the beginning of the year to the (Example) date, or the "138" part of your julian date.

MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top