Customizing date format output

  • Thread starter Thread starter Imran Ghani
  • Start date Start date
I

Imran Ghani

Hi! Its nice to be among all of you programming genius people. I am working
in MS Access2007 with VBA programming. I want to develop a unique id for my
records, thereby I need to convert my Date() to the format of "ddmmyyyy" e.g.
17062009, the dd/mm/yyyy format w/o the "/" option. I hav tried many options
but still not succeeded. I'd much appreciate if anybody could suggest me the
right way to achieve it. Thanks in advance.
 
I do this with date/time variables all the time, specifically for filenames.
Keep in mind Format() returns a string.

So assuming Now() is 02/28/2009 3:15:02AM, gets converted as so:

strVariable = "Format(Now(), "yyyymmddhhmmss")

?strVariable
20090228031502



hth
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
Hi! Its nice to be among all of you programming genius people. I am working
in MS Access2007 with VBA programming. I want to develop a unique id for my
records, thereby I need to convert my Date() to the format of "ddmmyyyy" e.g.
17062009, the dd/mm/yyyy format w/o the "/" option. I hav tried many options
but still not succeeded. I'd much appreciate if anybody could suggest me the
right way to achieve it. Thanks in advance.

FWIW, you might want to use YYYYMMDD so the records will sort in the
correct date order otherwise, you'll get all the records from the
first day of each month together. And, as Jack mentioned above,
including the time will give you a better shot at a unique key.

Hope this helps,
Chris M.
 
Hi! Its nice to be among all of you programming genius people. I am working
in MS Access2007 with VBA programming. I want to develop a unique id for my
records, thereby I need to convert my Date() to the format of "ddmmyyyy" e.g.
17062009, the dd/mm/yyyy format w/o the "/" option. I hav tried many options
but still not succeeded. I'd much appreciate if anybody could suggest me the
right way to achieve it. Thanks in advance.

I'd really have to question using a date as a unique key. Ok, right now, you
will never, ever have two records with the same date. But what's your
guarantee that next week the boss won't say "Oh, I forgot to mention, we need
to have data from all six branches in this database, and they'll all be
generating one record a day..."?

Dates ARE DATA. I'd store them as data, and use either a hidden, meaningless
autonumber, or a sequetially assigned record number, rather than making a date
value serve two (possibly incompatible) purposes.
 
Thanks for your prompt guidance. It seems not so difficult, but the problem
was that I'd to set the return variable's datatype as string, which I'd set
as date. So, its working all well now.
 
Back
Top