Click here to Skip to main content
15,915,724 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionSending Commands to cmd.exe Pin
gte999s26-Oct-05 13:53
gte999s26-Oct-05 13:53 
QuestionBrowsing remote files Pin
Member 227600326-Oct-05 12:42
Member 227600326-Oct-05 12:42 
AnswerRe: Browsing remote files Pin
enjoycrack26-Oct-05 13:23
enjoycrack26-Oct-05 13:23 
QuestionCountDown between dates Pin
im_hoser26-Oct-05 10:00
im_hoser26-Oct-05 10:00 
AnswerRe: CountDown between dates Pin
KaptinKrunch26-Oct-05 10:31
KaptinKrunch26-Oct-05 10:31 
GeneralRe: CountDown between dates Pin
im_hoser26-Oct-05 10:59
im_hoser26-Oct-05 10:59 
AnswerRe: CountDown between dates Pin
rwestgraham26-Oct-05 13:03
rwestgraham26-Oct-05 13:03 
AnswerRe: CountDown between dates Pin
George B Gilbert27-Oct-05 7:45
George B Gilbert27-Oct-05 7:45 
im_hoser...

The message displayed at the end of the below code displays the correct 2 years, 8 months, 2 weeks and 3 days. The only protection missing is checking, before this code is executed, whether or not the from date is after the to date; but, I'm sure you have that covered already.

This looks like a very useful routine. Think I'll put it into a Double Text library so I have it whenever I need it.

George

Dim Years As Integer
Dim Months As Integer
Dim Weeks As Integer
Dim Days As Integer

'** Create a couple of dates to play with
Dim TempDate As Date ' Working date
Dim FDate As Date = Now ' The first, or from date
Dim LDate As Date = DateAdd(DateInterval.Year, 2, FDate)
LDate = DateAdd(DateInterval.Month, 8, LDate)
LDate = DateAdd(DateInterval.Day, 17, LDate) ' The last, or to date

'** Determine the number of years in the interval
Years = DateDiff(DateInterval.Month, FDate, LDate)
Years = (Years - (Years Mod 12)) / 12
'** Advance the first date up by the number of years
FDate = DateAdd(DateInterval.Year, Years, FDate)

'** Determine the number of whole months
'** Calculate the raw number of months
Months = DateDiff(DateInterval.Month, FDate, LDate)
'** Set up a temporary date that is the first date advanced by
'** the number of raw months
TempDate = DateAdd(DateInterval.Month, Months, FDate)
'** If the raw number of months is too many, back off by 1 month
If DateDiff(DateInterval.Day, TempDate, LDate) < 0 Then
Months -= 1
End If
'** Advance the first date by the number of months
FDate = DateAdd(DateInterval.Month, Months, FDate)

'** Determine the number of weeks and days
Weeks = DateDiff(DateInterval.Day, FDate, LDate)
Days = Weeks Mod 7
Weeks = (Weeks - Days) / 7

MsgBox(Years & ControlChars.CrLf & _
Months & ControlChars.CrLf & _
Weeks & ControlChars.CrLf & _
Days & ControlChars.CrLf)
AnswerRe: CountDown between dates Pin
George B Gilbert27-Oct-05 8:25
George B Gilbert27-Oct-05 8:25 
GeneralRe: CountDown between dates Pin
im_hoser27-Oct-05 14:20
im_hoser27-Oct-05 14:20 
QuestionInstallation on a remote computer. Pin
Jim Wilcox26-Oct-05 8:07
Jim Wilcox26-Oct-05 8:07 
AnswerRe: Installation on a remote computer. Pin
rwestgraham26-Oct-05 14:48
rwestgraham26-Oct-05 14:48 
Questionsql problem Pin
microuser_200026-Oct-05 6:09
microuser_200026-Oct-05 6:09 
AnswerRe: sql problem Pin
Joshua Quick26-Oct-05 8:14
Joshua Quick26-Oct-05 8:14 
GeneralRe: sql problem Pin
microuser_200026-Oct-05 8:25
microuser_200026-Oct-05 8:25 
GeneralRe: sql problem Pin
Joshua Quick26-Oct-05 9:01
Joshua Quick26-Oct-05 9:01 
GeneralRe: sql problem Pin
microuser_200026-Oct-05 11:09
microuser_200026-Oct-05 11:09 
QuestionRemove Duplications Pin
stevelam26-Oct-05 5:27
stevelam26-Oct-05 5:27 
AnswerRe: Remove Duplications Pin
George B Gilbert26-Oct-05 7:02
George B Gilbert26-Oct-05 7:02 
GeneralRe: Remove Duplications Pin
stevelam26-Oct-05 8:21
stevelam26-Oct-05 8:21 
AnswerRe: Remove Duplications Pin
George B Gilbert26-Oct-05 8:30
George B Gilbert26-Oct-05 8:30 
GeneralRe: Remove Duplications Pin
stevelam26-Oct-05 8:35
stevelam26-Oct-05 8:35 
AnswerRe: Remove Duplications Pin
George B Gilbert27-Oct-05 6:15
George B Gilbert27-Oct-05 6:15 
QuestionOverriding the Built-In Menus and Commands in Microsoft Word Pin
microuser_200025-Oct-05 23:40
microuser_200025-Oct-05 23:40 
Questiondatagrid that does not display null for blank data...how it is possible Pin
ajay bharti25-Oct-05 21:05
ajay bharti25-Oct-05 21:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.