By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,730 Members | 1,500 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,730 IT Pros & Developers. It's quick & easy.

Getting the right date....

P: n/a
I have a form where I would like to get the todays date and when the date is
15 or less I would like to assign a textfield the last date of previous
month
and when the date is larger then 15 I need to set the textfield to the 15:th
of present month....

The code is wrong I know, but to clearify a little how I'm thinking:

If Date.Now <= 15 Then

txtTo.Text = lastday(Date.Now-1month)

Else

txtTo.Text = date.15

End If

Regards

/Drygast


Nov 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
probably not the cleanest sollution but it works

Dim strtest As String

Dim strresult As String

strtest = "15/" & Now.Month & "/" & Now.Year

If Now > strtest Then

strresult = "15/" & Now.Month & "/" & Now.Year

Else

Dim intm, intj As Int16

intj = Now.Year

intm = Now.Month - 1

If intm = 0 Then

intm = 12

intj -= 1

End If

strresult = "15/" & intm & "/" & intj

MessageBox.Show(strresult, "test")

End If
"Drygast" <dr*****@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have a form where I would like to get the todays date and when the date is 15 or less I would like to assign a textfield the last date of previous
month
and when the date is larger then 15 I need to set the textfield to the 15:th of present month....

The code is wrong I know, but to clearify a little how I'm thinking:

If Date.Now <= 15 Then

txtTo.Text = lastday(Date.Now-1month)

Else

txtTo.Text = date.15

End If

Regards

/Drygast

Nov 20 '05 #2

P: n/a
Cor
Hi Drygast
I have a form where I would like to get the todays date and when the date is 15 or less I would like to assign a textfield the last date of previous
month
and when the date is larger then 15 I need to set the textfield to the 15:th of present month....
The code is wrong I know, but to clearify a little how I'm thinking:
If Date.Now <= 15 Then
txtTo.Text = lastday(Date.Now-1month)
Else
txtTo.Text = date.15
End If


Does this looks like it?

\\\
Dim a As System.DateTime
If Now.Day < 15 Then
a = New System.DateTime(Now.Year, Now.Month, 15)
Else
If Now.Month = 1 Then
a = New System.DateTime(Now.Year - 1, 12, 15)
Else
a = New System.DateTime(Now.Year, Now.Month - 1, 15)
End If
End If
MessageBox.Show(a.ToString)
///
Cor
Nov 20 '05 #3

P: n/a
"Drygast" <dr*****@hotmail.com> schrieb
I have a form where I would like to get the todays date and when the
date is 15 or less I would like to assign a textfield the last date
of previous month
and when the date is larger then 15 I need to set the textfield to
the 15:th of present month....

The code is wrong I know, but to clearify a little how I'm
thinking:

If Date.Now <= 15 Then

txtTo.Text = lastday(Date.Now-1month)

Else

txtTo.Text = date.15

End If


Dim d As Date = Date.Today

If d.Day <= 15 Then
d = d.AddDays(-d.Day)
Else
d = d.AddDays(15 - d.Day)
End If

txtTo.Text = d.ToString
--
Armin

Nov 20 '05 #4

P: n/a
Thanks EricJ, Armin and Cor
you've all suggested similar solutions which work perfectly! Thanks!

But I also need to get the last date of previous month (doesn't work just
setting the date to 31)

recap:
If the date is < 15 then I need to get the last date (highest possible date
for instance 28 for febuary) in the previous month.

"Cor" <no*@non.com> wrote in message
news:3f***********************@reader20.wxs.nl...
Hi Drygast
I have a form where I would like to get the todays date and when the
date is
15 or less I would like to assign a textfield the last date of previous
month
and when the date is larger then 15 I need to set the textfield to the

15:th
of present month....
The code is wrong I know, but to clearify a little how I'm thinking:
If Date.Now <= 15 Then
txtTo.Text = lastday(Date.Now-1month)
Else
txtTo.Text = date.15
End If


Does this looks like it?

\\\
Dim a As System.DateTime
If Now.Day < 15 Then
a = New System.DateTime(Now.Year, Now.Month, 15)
Else
If Now.Month = 1 Then
a = New System.DateTime(Now.Year - 1, 12, 15)
Else
a = New System.DateTime(Now.Year, Now.Month - 1, 15)
End If
End If
MessageBox.Show(a.ToString)
///
Cor

Nov 20 '05 #5

P: n/a
Cor
Hi Drygast,
I made that first, and then I thought you wanted something else,
This is something the same as Armin made the rest you have to do yourself.
(Did not check the code on typing errors I changed it at the last moment)
\\\
Dim a As String
If now.day > 15 Then
a = (now.day - (System.DateTime.DaysInMonth(Now.Year, Now.Month))).ToString
Else
a = now.day.ToString
End If
MessageBox.Show(a)
///
Cor

Nov 20 '05 #6

P: n/a


If Date.Now <= 15 Then
txtTo.Text = dateserial(date.now.year, date.now.month, 0)
Else

txtTo.Text = date.15

End If


"Drygast" <dr*****@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have a form where I would like to get the todays date and when the date is 15 or less I would like to assign a textfield the last date of previous
month
and when the date is larger then 15 I need to set the textfield to the 15:th of present month....

The code is wrong I know, but to clearify a little how I'm thinking:

If Date.Now <= 15 Then

txtTo.Text = lastday(Date.Now-1month)

Else

txtTo.Text = date.15

End If

Regards

/Drygast

Nov 20 '05 #7

P: n/a
the 15th of present date is:

dateserial(date.now.year, date.now.month+1,15)

hope this helps

re, habix

"Drygast" <dr*****@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I have a form where I would like to get the todays date and when the date is 15 or less I would like to assign a textfield the last date of previous
month
and when the date is larger then 15 I need to set the textfield to the 15:th of present month....

The code is wrong I know, but to clearify a little how I'm thinking:

If Date.Now <= 15 Then

txtTo.Text = lastday(Date.Now-1month)

Else

txtTo.Text = date.15

End If

Regards

/Drygast

Nov 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.