Handling some universal functions (VB) for DateTime in ASP.NET Reposted: Andy.M Date: 2003-07-12 Popularity: 69'Uses The Timespan Method To Subtract a CERTAIN NUMBER OF DaySFunction Date1 () Dim NewTime As datetime newtime = DateTime.now.subtract (New Timespan (7, 0, 0, 0)) NewTIME = NewTime.Format ("mm / dd / yyyy", datetimeformatinfo) response.write (newtime) End Function'Uses The AddDays Method to Subtract X number of daysPublic Function Date2 () Dim NewTime as DateTime NewTime = DateTime.Now.AddDays (-7) Dim s as string = NewTime return sEnd Function'Thanks to Paul Czywczynski for this idea'This probably (In My opinion) Offers the most Flexibility Found So Far'change WHERE THEVER'RESPONSE.WRITE ("{0: D}" ("{0: D}", newtime) 'Would Return Just the name of the dayfunction date3 () DIM NewTime as DateTime = now.addDays (-7) response.write (System.String.Format ( "{0: MM / dd / yyyy}", NewTime)) End FunctionFunction Date4 () Dim NewTime as DateTime NewTime = now.addDays (-7) Return NewTime.toString () EN d Function 'Uses the toLongTimeString methodPublic Function Date5 () Dim NewTime as DateTime NewTime = Now () return newtime.toLongTimeString () End Function'Uses the toShortTimeString methodPublic Function Date6 () Dim NewTime as DateTime NewTime = Now () return newtime.toShortTimeString () End Function'Uses the toLongDateString methodPublic Function Date7 () Dim NewTime as DateTime NewTime = Now () return newtime.toLongDateString () End Function'Uses the toShortDateString methodPublic Function Date8 () Dim NewTime as DateTime NewTime = Now () return newtime .toshortdateString () end function '
Uses FormatDateTime function General formatFunction Date9 () Dim NewTime as DateTime NewTime = DateTime.Now.Subtract (New TimeSpan (7, 0, 0, 0)) return formatdatetime (NewTime, 0) End Function'Uses FormatDateTime function LongDate formatFunction Date10 () Dim NewTime as DateTime NewTime = DateTime.Now.Subtract (New TimeSpan (7, 0, 0, 0)) return formatdatetime (NewTime, 1) End Function'Uses FormatDateTime function ShortDate formatFunction Date11 () Dim NewTime as DateTime NewTime = DateTime. Now.Subtract (New TimeSpan (7, 0, 0, 0)) return formatdatetime (NewTime, 2) End Function'Uses FormatDateTime function LongTime formatFunction Date12 () Dim NewTime as DateTime NewTime = DateTime.Now.Subtract (New TimeSpan (7 , 0, 0, 0)) return formatdatetime (NewTime, 3) End Function'Uses FormatDateTime function ShortTime formatFunction Date13 () Dim NewTime as DateTime NewTime = DateTime.Now.Subtract (New TimeSpan (7, 0, 0, 0)) Return Formator (NewTime, 4) End Function'Bring Back Just The Name Dim newtime as date14 () DIM newTime as datetime = now.adddays (-7) DIM S AS STRING S = (System.String.Format ("{0: DDDD}", newtime) Return Send Function'Returns the Integer of what day of weekFunction Date15 () Dim MyDate as DateTime Dim MyWeekDay as Integer MyDate = Now.AddDays (-5) MyWeekDay = Weekday (MyDate) return MyWeekDayEnd Function'Returns the Month IntegerFunction Date16 () Dim MyDate as DateTime Dim MyMonth as Integer MyDate = Now.adddays (-5) MyMonth = Month (mydate) Return MyMonthend Function'Returns Just A formatted string'this method provides just formatting but '