Putting together a date... 
Author Message
 Putting together a date...

Now if I ask the user in my program to input a date, a month and a
year, how do I put those three together to make a legal and accurate
Date variable?

Michael K. P.



Sat, 31 Jan 2004 09:06:31 GMT  
 Putting together a date...
Use the CDate() function.  Ex:

MyDate = CDate(USMonth & "/" & USDay & "/" & USYear)

Note though that that is locale aware, so you might end up with days and months
swapped when working with the United States and Europe or something.

Howard Henry Schlunder



Quote:
> Now if I ask the user in my program to input a date, a month and a
> year, how do I put those three together to make a legal and accurate
> Date variable?

> Michael K. P.



Sat, 31 Jan 2004 10:34:03 GMT  
 Putting together a date...
"Michael Kragh Pedersen" wrote
 > Now if I ask the user in my program to input a date, a month and a
 > year, how do I put those three together to make a legal and accurate
 > Date variable?

From the Immediate Window:

 ? DateSerial(2001,8,13)
 8/13/2001

The DateSerial function is a built-in function to do just what you want.
Code it, put the cursor in the DateSerial function name and press F1 for
Help.



Sat, 31 Jan 2004 11:16:20 GMT  
 Putting together a date...


Quote:


> > Now if I ask the user in my program to input a date, a month and a
> > year, how do I put those three together to make a legal and accurate
> > Date variable?

> Use the CDate() function.  Ex:

> MyDate = CDate(USMonth & "/" & USDay & "/" & USYear)

> Note though that that is locale aware, so you might end up with days and
months
> swapped when working with the United States and Europe or something.

A "safer" way might be to do something along the lines of:

myDate = DateAdd("yyyy", myYear - 1900, myDate)
myDate = DateAdd("m", myMonth - 1, myDate)
myDate = DateAdd("d", myDay + 1, myDate)

This shouldn't matter which format your dates are set to in Windows.

Rob.



Sat, 31 Jan 2004 11:27:34 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How do I put different files together?

2. ADO Put a space between 2 fields concatenated together in .ListField property

3. Database strings won't be put together

4. Network adapter question: how to put ip address and MAC addresses together

5. Put value and string together to object name

6. Putting Puzzles back together?

7. How do I put different files together?

8. Help to put together a Web Form

9. Put it all together

10. Put it all together (2)

11. putting string together

12. Putting together wav fles

 

 
Powered by phpBB® Forum Software