Working with a date string

C

Charlie

I was going to use an input box to ask the user for a date but I'm not sure
the type of object it should be. I don't want it as a String because I need
to use the date in this way to export it as a calendar event. In the InputBox
default I could put something like "1/27/06" and have the message to prompt
them to follow this format, but that wouldn't be an integer then. I also
need to calculate another date from their input, like 3 days after the day
that they input, so a String wouldn't work either would it?
Stumped,
Charlie
 
J

Jezebel

Read Help on the date functions. The best data entry method is to use one of
the date controls like DatePicker or Calendar, which is guaranteed to return
a valid date; next best is to let the user enter the date as a string then
use CDate() or DateValue() to convert it then display the converted value
back to the user. The conversions in both directions should use the user's
own regional settings rather than assuming m/dd/yy (as you seem inclined to
do -- *most* of the world does not use that format).

To calculate another date from a given date you can use the DateAdd()
function; or if you are dealing with simple day offsets you can just
add/subtract. (And forget about integers. Internally, dates are doubles.)
 
K

Kevin B

I you go the Input Box route, in addition to the aforementioned formula
functions (CDate(), DateValue()) you can use the IsDate() function to
determine if the entry can be read as a vaild date.
 
J

Jezebel

IsDate() has a rather poor reputation. The function returns true for times
as well as dates, so it accepts entries like "23:59:59" and "1.1.1" -- on
the other hand it rejects legitimate foreign language dates like "4 Enero
2006".
 

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

Top