VB.Net 2005, how can I subtract a date from (current date minus 7 days) and create a few days?

I have a date in the future, for example. 10/13/2008 I need to subtract the current date (today 09/28/2010) minus 7 days, so 09/21/2010 minus 10/13/2008, which is equal to erm, 720 something?

But the current date will not always be 09/28/2010, obviously.

I need code for this.

EDIT: When I said the future, I mean the past :)

+3
source share
4 answers
Sub Main()
    Dim dt As DateTime = New DateTime(2008, 10, 13)
    ' be careful what you are subtracting from what
    ' the date you have is not in the future (year 2008)
    ' if the date is in the future: (dt.Subtract(DateTime.Now.AddDays(-7))).TotalDays
    ' or simply take the absolute value
    Dim days As Double = (DateTime.Now.AddDays(-7).Subtract(dt)).TotalDays
    Console.WriteLine(days)
End Sub

You will also notice that the TotalDays property is of type Double .

+5
source

10/13/2008 not quite in the future :)

Sorry for using C # code, but:

(dateInFuture - DateTime.Now.AddDays(-7)).TotalDays

. , , :

(DateTime.Now.AddDays(-7) - dateInPast).TotalDays
+1
        Dim ValidDate As Date =cDate("Tuesday, December 31, 2013") 'A date in Future

        Dim date1 As New System.DateTime(ValidDate.Year, ValidDate.Month, ValidDate.Day)
        Dim date2 = Now

        Dim Diff1 As System.TimeSpan

        Diff1 = date1.Subtract(date2)

        Dim TotRemDays = (Int(Diff1.TotalDays))

        MsgBox(TotRemDays)
+1

" ", , "Plz give meh teh codez", " " .

DateTime, Subtract ( , ), TimeSpan.

DateTime , TimeSpan 7 , DateTime, (, , ). TimeSpan, , , Days.

, , AddDays DateTime.

0
source

Source: https://habr.com/ru/post/1766915/


All Articles