Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

# Number of Days Calculation

Posted on 2011-05-13
Medium Priority
372 Views
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 - ??
0
Question by:bhlabelle
• 4

LVL 9

Expert Comment

ID: 35753964
``````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)
``````
0

LVL 9

Expert Comment

ID: 35753976
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)
``````
0

LVL 9

Expert Comment

ID: 35753987

``````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)
``````
0

LVL 9

Accepted Solution

mayank_joshi earned 2000 total points
ID: 35754004
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)
``````
0

Author Closing Comment

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

0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Integration Management Part 2
Screencast - Getting to Know the Pipeline
###### Suggested Courses
Course of the Month14 days, 8 hours left to enroll