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
5
Medium Priority
?
372 Views
Last Modified: 2012-05-11
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
Comment
Question by:bhlabelle
  • 4
5 Comments
 
LVL 9

Expert Comment

by:mayank_joshi
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)

Open in new window

0
 
LVL 9

Expert Comment

by:mayank_joshi
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)

Open in new window

0
 
LVL 9

Expert Comment

by:mayank_joshi
ID: 35753987
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
 
LVL 9

Accepted Solution

by:
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)

Open in new window

0
 

Author Closing Comment

by:bhlabelle
ID: 35754276
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question