{"id":1465,"date":"2011-09-13T17:26:20","date_gmt":"2011-09-13T21:26:20","guid":{"rendered":"http:\/\/www.iowawebnet.com\/ein\/?p=1465"},"modified":"2011-11-11T11:13:18","modified_gmt":"2011-11-11T15:13:18","slug":"vb-net-date-in-code-behind","status":"publish","type":"post","link":"https:\/\/www.iowawebnet.com\/ein\/2011\/09\/vb-net-date-in-code-behind\/","title":{"rendered":"VB.NET &#8211; Date in code behind"},"content":{"rendered":"<blockquote><p>Here is example of how we can define date in code behind:<\/p><\/blockquote>\n<pre>Current month name\r\n<code> \r\n ' - label text for current month (e.i. September) \r\nCMonthLbl.Text = \"Current month is \" &amp; MonthName(Date.Now.Month).ToString() \r\n ' - label &lt;asp:label ID=\"CMonthLbl\" runat=\"server\"&gt; \r\n ' - output <\/code>\r\nCurrent month is September<\/pre>\n<blockquote><p>Other examples:<\/p><\/blockquote>\n<pre>Any month name\r\n<code> \r\n ' - your favorite month is June \r\nYourFavoriteMthLbl.Text = \"My favorite month is \" &amp; MonthName(6).ToString() \r\n ' - label \r\n&lt;asp:label ID=\"YourFavoriteMthLbl\" runat=\"server\"&gt;\r\n \u00a0' - output <\/code>\r\nMy favorite month is June<\/pre>\n<pre>First of the current month\r\n<code>\r\n ' - current date 09\/13\/2011\r\n ' - 1st of the month \r\nFirstOfMth.Text = \"From: \" &amp; DateTime.Now.Month.ToString() + \"\/1\/\" \r\n                   _+ DateTime.Now.Year.ToString() \r\n\u00a0' - label &lt;asp:label ID=\"FirstOfMth\" runat=\"server\"&gt; \r\n ' - output <\/code>\r\nFrom: 09\/01\/2011\r\nMonth from now\r\n<code> \r\n ' - current date 09\/13\/2011 \r\n\u00a0' - last day of the month \r\nMoFrmNow.Text = \"End: \" &amp; DateTime.Today.AddMonth(1).AddDay(0).ToString() \r\n ' - End: 09\/30\/2011 \r\n<\/code>\r\nLast day of the current month\r\n<code>\r\n ' define var\r\nDim cYear, cMonth\r\ncYear = DateTime.Now.Year 'current year needed for MoEnd range\r\ncMonth = DateTime.Now.Month\r\nMoEnd.Text = \"End of month: \" & Date.Now.Month.ToString() & \"\/\" \r\n                              & DateTime.DaysInMonth(cYear, cMonth) & \"\/\" \r\n                              & Date.Now.Year.ToString() & \".\"\r\n<\/code>\r\nEnd of month: 9\/30\/2011\r\n<\/pre>\n<pre>Next to the current month\r\n<code>\r\n ' - current date 09\/13\/2011 \r\nDim NxtMth As String NxtMth = DateTime.Now.Month + 1 \r\n\u00a0' - current month end or next to current month \r\nNextToCurMth.Text = \"To: \" &amp; NxtMth.ToString() + \"\/1\/\" _ + DateTime.Now.Year.ToString() \r\n\u00a0' - label &lt;asp:label ID=\"NextToCurMth\" runat=\"server\"&gt; \r\n\u00a0' - output <\/code>\r\nTo: 10\/01\/2011<\/pre>\n<pre>Current date in textbox\r\n<code> \r\n ' - code behind \r\nProtected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load \r\nDateTxtBx.Text = \"Today is: \" &amp; _ DateTime.Now.ToShortDateString() \r\nDateTxtBx1.Text = \"Different date format: \" &amp; _ DateTime.Now.Year.ToString() + \".\" \u00a0\r\n                  _ + DateTime.Now.Month.ToString() + \".\" \r\n                  _ + DateTime.Now.Day.ToString() \r\nEnd Sub\r\n ' - textbox .NET control \r\n&lt;asp:TextBox ID=\"DateTxtBx\" runat=\"server\"&gt; \r\n\u00a0' - date as 09\/14\/2011 &lt;asp:TextBox ID=\"DateTxtBx1\" runat=\"server\"&gt; \r\n\u00a0' - date as 2011.9.14 ' - output \r\n<\/code>\r\nToday is:\r\n<input style=\"width: 80px; height: 22px; padding-left: 2px;\" type=\"text\" value=\"09\/14\/2011\" disabled=\"disabled\" \/>\r\nDifferent day format:\r\n<input style=\"width: 80px; height: 22px; padding-left: 2px;\" type=\"text\" value=\"2011.9.14\" disabled=\"disabled\" \/><\/pre>\n<p><strong>View related posts:<\/strong><br \/>\n&#8211; <a href=\"http:\/\/www.iowawebnet.com\/ein\/2011\/11\/month-day-and-year-code-behind-format\/\">Month, day and year code behind format<\/a><br \/>\n&#8211; <a href=\"http:\/\/www.iowawebnet.com\/ein\/2011\/08\/vb-net-date-and-time-format\/\">VB.NET date and time format<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is example of how we can define date in code behind: Current month name &#8216; &#8211; label text for current month (e.i. September) CMonthLbl.Text = &#8220;Current month is &#8221; &amp; MonthName(Date.Now.Month).ToString() &#8216; &#8211; label &lt;asp:label ID=&#8221;CMonthLbl&#8221; runat=&#8221;server&#8221;&gt; &#8216; &#8211; output Current month is September Other examples: Any month name &#8216; &#8211; your favorite month [&hellip;]<\/p>\n","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,57],"tags":[58,60,59],"class_list":["post-1465","post","type-post","status-publish","format-standard","hentry","category-applications","category-date-and-time-format","tag-date","tag-format","tag-time"],"_links":{"self":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/1465"}],"collection":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/comments?post=1465"}],"version-history":[{"count":25,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/1465\/revisions"}],"predecessor-version":[{"id":1704,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/1465\/revisions\/1704"}],"wp:attachment":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/media?parent=1465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/categories?post=1465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/tags?post=1465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}