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

Casting to date

P: n/a

All.

I have three variables M, D, and Y that take input from DomainUpDown
(prefix dud_) and NumericUpDown (prefix nud_). How do I cast these
into a valid date-time data type?
The DomainUPDown contains full month naes as text, eg January,
February, ect.

Dim Input_Date As Date

M = dud_Month.SelectedIndex
D = nun_Day.Value
Y = nun_Year.Value

These lines complie but fail at runtime.

Input_Date = DateValue(Dud_Month.Name + "/" + CStr(Nud_Day.Value) +
"," + CStr(Nud_Year.Value))

Input_Date = DateValue(Cstr(Y +1)+ "/" + CStr(D) + "/" + CStr(Y))
The idea is to compate the constructed date (using datediff) with
today too see if a future date has been selected.

Any suggestions would be welcome.

Rob.B
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Rob,
If M, D, an Y are integers, why not simply use the constructor for DateTime?

Something like:

Dim month, day, year As Integer
month = dud_Month.SelectedIndex
day = nun_Day.Value
year = nun_Year.Value

Dim inputDate As New DateTime(year, month, day)

If DateTime.Compare(inputDate, DateTime.Today) > 0 Then
' date is in the future
End If

For details on the DateTime constructor & DateTime.COmpare see the on-line
help for the DateTime Structure. Remember that Date is an alias for
System.DateTime.

Hope this helps
Jay

"Rob Bradford" <ro**********@lvirgin.net> wrote in message
news:3c********************************@4ax.com...

All.

I have three variables M, D, and Y that take input from DomainUpDown
(prefix dud_) and NumericUpDown (prefix nud_). How do I cast these
into a valid date-time data type?
The DomainUPDown contains full month naes as text, eg January,
February, ect.

Dim Input_Date As Date

M = dud_Month.SelectedIndex
D = nun_Day.Value
Y = nun_Year.Value

These lines complie but fail at runtime.

Input_Date = DateValue(Dud_Month.Name + "/" + CStr(Nud_Day.Value) +
"," + CStr(Nud_Year.Value))

Input_Date = DateValue(Cstr(Y +1)+ "/" + CStr(D) + "/" + CStr(Y))
The idea is to compate the constructed date (using datediff) with
today too see if a future date has been selected.

Any suggestions would be welcome.

Rob.B

Nov 21 '05 #2

P: n/a
Rob,

Assuming you are in an arrea of the world where the date is used as in the
USA and in Aglo Canada, than it should be (untested)

\\\
dim Input_Date as DateTime = CDate(DateValue(Dud_Month.Name + "/" + Nud_Day
+
"/" + Nud_Year)

///

When it is important to globalize, than you should use the number of the
month and that I never did, however by first create a table using the month
function, seems that as well for me very easy (when it is a problem reply)?

I hope this helps so far?

Cor
Nov 21 '05 #3

P: n/a
Thanks to everyone who replied, it was a great help.

On Sun, 3 Oct 2004 06:29:27 +0000 (UTC), Rob Bradford
<ro**********@lvirgin.net> wrote:

All.

I have three variables M, D, and Y that take input from DomainUpDown
(prefix dud_) and NumericUpDown (prefix nud_). How do I cast these
into a valid date-time data type?
The DomainUPDown contains full month naes as text, eg January,
February, ect.

Dim Input_Date As Date

M = dud_Month.SelectedIndex
D = nun_Day.Value
Y = nun_Year.Value

These lines complie but fail at runtime.

Input_Date = DateValue(Dud_Month.Name + "/" + CStr(Nud_Day.Value) +
"," + CStr(Nud_Year.Value))

Input_Date = DateValue(Cstr(Y +1)+ "/" + CStr(D) + "/" + CStr(Y))
The idea is to compate the constructed date (using datediff) with
today too see if a future date has been selected.

Any suggestions would be welcome.

Rob.B


Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.