Casting to date

  • Thread starter Thread starter Rob Bradford
  • Start date Start date
R

Rob Bradford

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
 
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,

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top