• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 516
  • Last Modified:

How to get the difference in days between two dates using asp.net 2.0 and vb.net?

HI

I would like to get the difference in days between two dates using asp.net 2.0 and vb.net

Thanks in advace.
0
dimensionav
Asked:
dimensionav
  • 2
1 Solution
 
isaackhaziCommented:
U mean the number of days betwween two specified days??
 Dim txtDate1 As Date = CType(Me.TextBox1.Text, Date) 
   Dim txtDate2 As Date = CType(Me.TextBox2.Text, Date) 
   Dim MyDifference As TimeSpan 
 
        MyDifference = txtDate2.Subtract(txtDate1) ' find the number of days apart 
        MessageBox.Show(MyDifference.Days) ' Display to the user

Open in new window

0
 
isaackhaziCommented:
In C# you could do something lie this"
DateTime startTime = DateTime.Now;
 
 DateTime endTime = DateTime.Now.AddSeconds( 75 );
 
 TimeSpan span = endTime.Subtract ( startTime );
 Console.WriteLine( "Time Difference (seconds): " + span.Seconds );
 Console.WriteLine( "Time Difference (minutes): " + span.Minutes );
 Console.WriteLine( "Time Difference (hours): " + span.Hours );
 Console.WriteLine( "Time Difference (days): " + span.Days );

Open in new window

0
 
dimensionavAuthor Commented:
It worked pretty well, Thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now