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 :)
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 .
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
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)
" ", , "Plz give meh teh codez", " " .
DateTime, Subtract ( , ), TimeSpan.
DateTime
TimeSpan
DateTime , TimeSpan 7 , DateTime, (, , ). TimeSpan, , , Days.
Days
, , AddDays DateTime.
AddDays
Source: https://habr.com/ru/post/1766915/More articles:Where will the session value be stored in PHP - phpJCombobox adds different colors to each element - javaПоместите загруженные письма на сервер POP3 - uploadHow to refer to a Grails GSP model variable indirectly, for example. via .get (...) - mapcreating a symbolic link from the selected file type in the folder - linuxGWT vertical tabs such as iGoogle - gwtJavaScript error "null or not object" - javascript.Net / WinForms Docking / Floating Library for .Net 4.0 - c #Convert Null to Nullable Enum (generic) - genericsAutomating cygwin through a batch file - cygwinAll Articles