473,320 Members | 1,884 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,320 software developers and data experts.

Casting to date


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
3 1157
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: maxim vexler | last post by:
in a book i am ready now : O'Reilly - Web Database Application with PHP and MySQL, 2nd ed. by David Lane, Hugh E. Williams on chapter 9 the author give an example for age validation :...
231
by: Brian Blais | last post by:
Hello, I saw on a couple of recent posts people saying that casting the return value of malloc is bad, like: d=(double *) malloc(50*sizeof(double)); why is this bad? I had always thought...
2
by: Zac | last post by:
Alright anyone who has 2c throw it in... I am working through a custom xml serializer and have come upon a conundrum, given our class design. The interface implemented on the base class (base...
3
by: Martin | last post by:
Hi, I have what is probabally a date contained in an object variable. Before casting to date I actually want to attempt to verify that I actually have a date. I prefer to do this before casting...
6
by: Jim C. Nasby | last post by:
Is there any reason why there isn't a predefined cast to go from a timestamp to a varchar? Is there a reason not to add one? -- Jim C. Nasby, Database Consultant jim@nasby.net...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.