Number of Days Calculation

Ok, trying to keep this as easy as possible.  I need to find the best way to find out how many days from the beginning of a year to a date that is entered by the user into a text box.

Dim DateEntered as Date
Dim NumDays as Long

DateEntered = TextBox1.value
This is probably where I need to take the year from the date and work with that, which is my ??
NumDays = DateEntered - ??
bhlabelleAsked:
Who is Participating?
 
mayank_joshiCommented:
sorry for making repetitive mistakes.
this should work:-

Dim DateEntered As Date
        Dim NumDays As Long
        DateEntered = CDate(TextBox1.text)
        Dim YearStartDate As Date = CDate("1/1/" & Today.Year)
        NumDays = DateDiff(DateInterval.Day, YearStartDate, DateEntered)

Open in new window

0
 
mayank_joshiCommented:
Dim DateEntered As Date
        Dim NumDays As Long
        DateEntered = CDate("TextBox1.text")
        Dim YearStartDate = CDate("1/1/" & Today.Year)
        NumDays = DateDiff(DateInterval.Day, YearStartDate, DateEntered)

Open in new window

0
 
mayank_joshiCommented:
sorry some corrections:-
Dim DateEntered As Date
        Dim NumDays As Long
        DateEntered = CDate(TextBox1.text)
        Dim YearStartDate = CDate("1/1/" & Today.Year)
        NumDays = DateDiff(DateInterval.Day, YearStartDate, DateEntered)

Open in new window

0
 
mayank_joshiCommented:
try this please:-

Dim DateEntered As Date
        Dim NumDays As Long
        DateEntered = CDate(TextBox1.text)
        Dim YearStartDate As Date = CDate("1/1" & Today.Year)
        NumDays = DateDiff(DateInterval.Day, YearStartDate, DateEntered)

Open in new window

0
 
bhlabelleAuthor Commented:
Works very nice.  The only change was since it might not be this year, I used "CDate("1/1/" & DateEntered.Year)

I appreciate your help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.