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

Number of Day in year by entering the date

Status
Not open for further replies.

sdimaggio

Technical User
Jan 23, 2002
138
US
This may seem silly, but how do you calculate the day of the year by entering a date.

For example: 4/1/02 = 90 days.

thanks.
 
how about:

dim iDays as integer

iDays = DateDif("2002/1/1","2002/4/1","d") Hope this is ok. If not, just let me know.

Nick (Everton Rool OK!)
 
What I am trying to do is just enter any given date and end up with the number of the day of the year.

ie. 4/01/02 = 90

ie. 5/01/02 = 120

ie. 5/15/02 = 135

your code will work if I can figure out how to set the start date to Jan 1 of the current year automatically so when a new year arrives it will be right.

Thanks.
 
If u have a form, create a text box and place this code in the after update of the text box:

MsgBox DateDiff("d", "01/01/2002", txtdate)

where txtdate is the name of your text box. Hope this is ok. If not, just let me know.

Nick (Everton Rool OK!)
 
Still having trouble with what you are saying.

the code will have been written with 1/1/02 in it. When the year changes, I will have to go back and change it.

There has to be a better way, any ideas?

thanks

Steve
 
How about:

MsgBox DateDiff("d", "01/01/" & Year(Date), txtDate) Hope this is ok. If not, just let me know.

Nick (Everton Rool OK!)
 
Actually.....

There's a built-in function for this....

DatePart(dte, y) returns the day of the year...

Craig
 
Craig,

Could you please give an example on the date function

Control Source: = DatePart(dte,y)

Thanks

Steve
 
Actually shouldn't it be:
=DatePart("y",[Your txtbox])
Where [Your txtbox] is a textbox where you enter a date?
Jim
 
Jim,

You're right Thanks a million and to everyone else who posted on this.

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top