anther date question

S

Southern at Heart

StrDate is assigned todays date with the Now function, the value looks like
this:
3/25/2010 10:36:48 PM

....I need the value to look like this:
2010/03/25
(the month and day have to be 2 digits)

How do I do this?
thanks.
 
D

Dirk Goldgar

Southern at Heart said:
StrDate is assigned todays date with the Now function, the value looks
like
this:
3/25/2010 10:36:48 PM

...I need the value to look like this:
2010/03/25
(the month and day have to be 2 digits)

How do I do this?
thanks.


Is StrDate a variable? if so, what type of variable is it? The prefix
"str" usually denotes a string, but sometimes prefixes can be misleading.

If you just want the date, and not the time, you can assign from the Date()
function, rather than Now() -- look in the online help for a comparison of
Date(), Time(), and Now().

Assuming StrDate is a string variable, then you need to format the date into
the desired string. Try this:

StrDate = Format(Date(), "yyyy/mm/dd")
 
S

Southern at Heart

Assuming StrDate is a string variable, then you need to format the date into
the desired string. Try this:

StrDate = Format(Date(), "yyyy/mm/dd")

....this should do it, as it needs to be a string.
Thanks. I've tried lots of different syntax with that Format function, but
couldn't quite get it.
Cheers.
 
S

Southern at Heart

When I run this code, it changes StartDate to todays date!
StartDate = Format(Date, "yyyy/mm/dd")
....StartDate was something else before it came to this line...
Please help, thanks.
(I'm needing the date to be in that format)
 
J

John W. Vinson

When I run this code, it changes StartDate to todays date!
StartDate = Format(Date, "yyyy/mm/dd")
...StartDate was something else before it came to this line...
Please help, thanks.
(I'm needing the date to be in that format)

That's precisely what you're telling it to do: call the built in Date()
function, convert it to a yyyy/mm/dd text string using the Format function,
and store that text string in StartDate.

What is the context? Is StartDate a variable, a form control, something else?
Do you have a form control or table field named Date? If so, you're running
into the main reason you should NOT do that - Access getting confused about
whether you mean the field or the builtin function!
 

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