473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to insert the last day of the month in a textbox.

txtToDate.Text = (Now.Date.AddDays(-(Now.Day)).AddMonths(1))

Nov 21 '05 #1
5 2506
Hi,
Dim intMonth As Integer = Now.Month

Dim intYear As Integer = Now.Year

Dim intDays As Integer = Now.DaysInMonth(intYear, intMonth)

Dim dtEnd As DateTime = New DateTime(intYear, intMonth, intDays)

TextBox1.Text = dtEnd.ToShortDateString

Ken

--------------------------------

"PAPutzback" <ph**************@insightbb.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
txtToDate.Text = (Now.Date.AddDays(-(Now.Day)).AddMonths(1))
Nov 21 '05 #2
I am not sure if there is a benefit to creating four variables as
opposed to the one line approach. Or maybe I am missing something that
won't show up until a leap year or something.
txtToDate.Text = (Now.Date.AddDays(-(Now.Day)).*AddMonths(1))

Nov 21 '05 #3
Paputzback,

Ken thought probably that it was a question. However with option strict on
the code will give an error. You need for that to add.

txtToDate.Text = (Now.Date.AddDays(-(Now.Day)).*AddMonths(1)).ToString

I hope this helps,

Cor
Nov 21 '05 #4
Thanks. I thought option strict was on by default.

Nov 21 '05 #5
PAPutzback,
In addition to the other comments, I would recommend:

Private Shared Function LastDayOfMonth(ByVal theDate As DateTime) As
DateTime
Dim day As Integer = DateTime.DaysInMonth(theDate.Year,
theDate.Month)
Return New DateTime(theDate.Year, theDate.Month, day)
End Function

Public Shared Sub Main()

Debug.WriteLine(LastDayOfMonth(DateTime.Now))

End Sub

Of course if you want to inline the day variable you could:

Return New DateTime(theDate.Year, theDate.Month, _
DateTime.DaysInMonth(theDate.Year, theDate.Month))

The *major* reason to use a function as above or at least use DateTime.Now
indirectly by assigning it to a variable is that DateTime.Now may change
during the equation, you could get very sporadic results at midnight on the
last day of the month, as DateTime.Now may change over from "this month" to
"next month" midway thru yours or Ken's algorithm. By assigning DateTime.Now
to a variable (or a parameter as above) you avoid any potential problems
with "now" changing.

Hope this helps
Jay

"PAPutzback" <ph**************@insightbb.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
| txtToDate.Text = (Now.Date.AddDays(-(Now.Day)).AddMonths(1))
|
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: PT | last post by:
I got a problem. And thats..... First of all, I got these three tables. ------------------- ------------------ ---------------------- tblPerson tblPersonSoftware ...
9
by: adi | last post by:
Hi all, Hope there is a quick fix for this: I am inserting data from one table to another on the same DB. The insert is pretty simple as in: insert into datatable(field1, field2, field3)...
3
by: Melissa | last post by:
I have this table: TblProjectYear ProjectYearID ProjectYearStartDate ProjectYearEndDate The Project Year will always span across December 31; for example 9/1/04 to 6/30/05. How do I build a...
1
by: Abareblue | last post by:
I have no clue on how to insert a record into access. here is the whole thing using System; using System.Drawing; using System.Collections; using System.ComponentModel;
1
by: tshad | last post by:
I can't seem to get insert into a DataGrid to work. I am using an example from the net and made changes to work on my computer. The grid comes up fine. The edit boxes in the footer are there. ...
7
by: Lorenzino | last post by:
Hi, I have a problem with bindings in a formview. I have a formview; in the insert template i've created a wizard control and inside it i have an HTML table with some textboxes bound to the...
3
by: remya1000 | last post by:
i'm using ASP with MSAccess as database. i have two buttons and two textbox in my page. when i press my first button (First month) i need to display the current month in one textbox and last one...
2
by: shapper | last post by:
Hello, I am working with a ListView but I suppose that with a GridView might be the same. Instead of having an Insert Button on each GridView row I would like to have only one Insert button,...
8
idsanjeev
by: idsanjeev | last post by:
this code repred error ERROR ORA-00936: missing expression <%@ Page Language="VB" %> <%@ import Namespace="System.Data.ODbc" %> <%@ import Namespace=" System.Data" %> <script runat="server"> ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.