VB.NET & DateAdd() - DateAdd() : Returns a Date value containing a date and time value to which a specified time interval has been added.
ShotDev Focus:
- VB.NET & DateAdd()
Syntax
DateAdd(DateInterval,Number,DateValue)
DateInterval
DateInterval.Day DateInterval.DayOfYear DateInterval.Hour DateInterval.Minute DateInterval.Month DateInterval.Quarter DateInterval.Second DateInterval.Weekday DateInterval.WeekOfYear DateInterval.Year
Example
DateAdd.aspx
<%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) Session.LCID = 1033 Dim strDate As Date strDate = "10/11/2008" Me.lblText1.Text = DateAdd(DateInterval.Day, 1, Date.Now) Me.lblText2.Text = DateAdd(DateInterval.Month, 1, Date.Now) Me.lblText3.Text = DateAdd(DateInterval.Year, 1, Date.Now) Me.lblText4.Text = DateAdd(DateInterval.Hour, 1, Date.Now) Me.lblText5.Text = DateAdd(DateInterval.Second, 1, Date.Now) Me.lblText6.Text = DateAdd(DateInterval.Minute, 1, strDate) End Sub </script> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <form runat="server"> <asp:Label id="lblText1" runat="server"></asp:Label><br /> <asp:Label id="lblText2" runat="server"></asp:Label><br /> <asp:Label id="lblText3" runat="server"></asp:Label><br /> <asp:Label id="lblText4" runat="server"></asp:Label><br /> <asp:Label id="lblText5" runat="server"></asp:Label><br /> <asp:Label id="lblText6" runat="server"></asp:Label><br /> </form> </body> </html>
Screenshot
.
.
.
Download this script.
.
.
.
VB.NET & AddYears() - AddYears() : Returns a new DateTime that adds the specified number of years to the value of this instance.
ShotDev Focus:
- VB.NET & AddYears()
Example
AddYears.aspx
<%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) Session.LCID = 1033 Dim strDate As DateTime strDate = "10/11/2008 08:25:30" Me.lblText1.Text = Now() Me.lblText2.Text = Now.AddYears(2) Me.lblText3.Text = Now.AddYears(-1) Me.lblText4.Text = strDate.AddYears(1) End Sub </script> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <form runat="server"> <asp:Label id="lblText1" runat="server"></asp:Label><br /> <asp:Label id="lblText2" runat="server"></asp:Label><br /> <asp:Label id="lblText3" runat="server"></asp:Label><br /> <asp:Label id="lblText4" runat="server"></asp:Label><br /> </form> </body> </html>
Screenshot
.
.
.
Download this script.
.
.
.
VB.NET & AddMonths() - AddMonths() : Returns a new DateTime that adds the specified number of months to the value of this instance.
ShotDev Focus:
- VB.NET & AddMonths()
Example
AddMonths.aspx
<%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) Session.LCID = 1033 Dim strDate As DateTime strDate = "10/11/2008 08:25:30" Me.lblText1.Text = Now() Me.lblText2.Text = Now.AddMonths(2) Me.lblText3.Text = Now.AddMonths(-1) Me.lblText4.Text = strDate.AddMonths(1) End Sub </script> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <form runat="server"> <asp:Label id="lblText1" runat="server"></asp:Label><br /> <asp:Label id="lblText2" runat="server"></asp:Label><br /> <asp:Label id="lblText3" runat="server"></asp:Label><br /> <asp:Label id="lblText4" runat="server"></asp:Label><br /> </form> </body> </html>
Screenshot
.
.
.
Download this script.
.
.
.
VB.NET & AddDays() - AddDays() : Returns a new DateTime that adds the specified number of days to the value of this instance.
ShotDev Focus:
- VB.NET & AddDays()
Example
AddDays.aspx
<%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) Session.LCID = 1033 Dim strDate As DateTime strDate = "10/11/2008 08:25:30" Me.lblText1.Text = Now() Me.lblText2.Text = Now.AddDays(2) Me.lblText3.Text = Now.AddDays(-1) Me.lblText4.Text = strDate.AddDays(1) End Sub </script> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <form runat="server"> <asp:Label id="lblText1" runat="server"></asp:Label><br /> <asp:Label id="lblText2" runat="server"></asp:Label><br /> <asp:Label id="lblText3" runat="server"></asp:Label><br /> <asp:Label id="lblText4" runat="server"></asp:Label><br /> </form> </body> </html>
Screenshot
.
.
.
Download this script.
.
.
.
VB.NET & AddHours() - AddHours() : Returns a new DateTime that adds the specified number of hours to the value of this instance.
ShotDev Focus:
- VB.NET & AddHours()
Example
AddHours.aspx
<%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) Session.LCID = 1033 Dim strDate As DateTime strDate = "10/11/2008 08:25:30" Me.lblText1.Text = Now() Me.lblText2.Text = Now.AddHours(2) Me.lblText3.Text = Now.AddHours(-1) Me.lblText4.Text = strDate.AddHours(1) End Sub </script> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <form runat="server"> <asp:Label id="lblText1" runat="server"></asp:Label><br /> <asp:Label id="lblText2" runat="server"></asp:Label><br /> <asp:Label id="lblText3" runat="server"></asp:Label><br /> <asp:Label id="lblText4" runat="server"></asp:Label><br /> </form> </body> </html>
Screenshot
.
.
.
Download this script.
.
.
.
VB.NET & AddMinutes() - AddMinutes() : Returns a new DateTime that adds the specified number of minutes to the value of this instance.
ShotDev Focus:
- VB.NET & AddMinutes()
Example
AddMinutes.aspx
<%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) Session.LCID = 1033 Dim strDate As DateTime strDate = "10/11/2008 08:25:30" Me.lblText1.Text = Now() Me.lblText2.Text = Now.AddMinutes(2) Me.lblText3.Text = Now.AddMinutes(-1) Me.lblText4.Text = strDate.AddMinutes(1) End Sub </script> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <form runat="server"> <asp:Label id="lblText1" runat="server"></asp:Label><br /> <asp:Label id="lblText2" runat="server"></asp:Label><br /> <asp:Label id="lblText3" runat="server"></asp:Label><br /> <asp:Label id="lblText4" runat="server"></asp:Label><br /> </form> </body> </html>
Screenshot
.
.
.
Download this script.
.
.
.
VB.NET & AddSeconds() - AddSeconds() : Returns a new DateTime that adds the specified number of seconds to the value of this instance.
ShotDev Focus:
- VB.NET & AddSeconds()
Example
AddSeconds.aspx
<%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) Session.LCID = 1033 Dim strDate As DateTime strDate = "10/11/2008 08:25:30" Me.lblText1.Text = Now() Me.lblText2.Text = Now.AddSeconds(2) Me.lblText3.Text = Now.AddSeconds(-1) Me.lblText4.Text = strDate.AddSeconds(1) End Sub </script> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <form runat="server"> <asp:Label id="lblText1" runat="server"></asp:Label><br /> <asp:Label id="lblText2" runat="server"></asp:Label><br /> <asp:Label id="lblText3" runat="server"></asp:Label><br /> <asp:Label id="lblText4" runat="server"></asp:Label><br /> </form> </body> </html>
Screenshot