PC Review


Reply
Thread Tools Rate Thread

Customizing date format output

 
 
Imran Ghani
Guest
Posts: n/a
 
      17th Jun 2009
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.
 
Reply With Quote
 
 
 
 
Jack Leach
Guest
Posts: n/a
 
      17th Jun 2009
strVar = Format(dateVar, "ddmmyyyy")

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)



"Imran Ghani" wrote:

> 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.

 
Reply With Quote
 
Jack Leach
Guest
Posts: n/a
 
      17th Jun 2009
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)



"Jack Leach" wrote:

> strVar = Format(dateVar, "ddmmyyyy")
>
> --
> Jack Leach
> www.tristatemachine.com
>
> "I haven''t failed, I''ve found ten thousand ways that don''t work."
> -Thomas Edison (1847-1931)
>
>
>
> "Imran Ghani" wrote:
>
> > 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.

 
Reply With Quote
 
mcescher
Guest
Posts: n/a
 
      17th Jun 2009
On Jun 17, 8:39*am, Imran Ghani <ImranGh...@discussions.microsoft.com>
wrote:
> 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.
 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      17th Jun 2009
On Wed, 17 Jun 2009 06:39:08 -0700, Imran Ghani
<(E-Mail Removed)> wrote:

>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.
--

John W. Vinson [MVP]
 
Reply With Quote
 
Imran Ghani
Guest
Posts: n/a
 
      18th Jun 2009
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.

"Jack Leach" wrote:

> strVar = Format(dateVar, "ddmmyyyy")
>
> --
> Jack Leach
> www.tristatemachine.com
>
> "I haven''t failed, I''ve found ten thousand ways that don''t work."
> -Thomas Edison (1847-1931)
>
>
>
> "Imran Ghani" wrote:
>
> > 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Forcing Date format as output? S Davis Microsoft Access 1 22nd Nov 2006 09:54 PM
Customizing MSDataSetGenerator output in VS2005 Stig Nielsson Microsoft C# .NET 3 8th Dec 2005 07:05 AM
Customizing MSDataSetGenerator output in VS2005 Stig Microsoft ADO .NET 1 6th Dec 2005 01:12 PM
Where can I set the output format of a database date field ? David Martin Microsoft Frontpage 6 17th Mar 2004 12:29 PM
customizing the short date format Candace Windows XP Setup 2 26th Nov 2003 01:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:01 AM.