create a unique id with year, month, day, hh,mm,ss

User avatar
sal21
PlatinumLounger
Posts: 4337
Joined: 26 Apr 2010, 17:36

create a unique id with year, month, day, hh,mm,ss

Post by sal21 »

when i click on command button, i need to crete a unique IDNAME...

For example, based time value:

IDNAME="09082021135228"

currdatehhmmss

Peraphs is one of my first question, about 15 year old :grin:

User avatar
HansV
Administrator
Posts: 78370
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: create a unique id with year, month, day, hh,mm,ss

Post by HansV »

That would be

Code: Select all

    IDNAME = Format(Now, "mmddyyyyhhnnss")
but I would prefer

Code: Select all

    IDNAME = Format(Now, "yyyymmddhhnnss")
because that would make it easy to sort the IDNAME values.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4337
Joined: 26 Apr 2010, 17:36

Re: create a unique id with year, month, day, hh,mm,ss

Post by sal21 »

HansV wrote:
08 Sep 2021, 12:36
That would be

Code: Select all

    IDNAME = Format(Now, "mmddyyyyhhnnss")
but I would prefer

Code: Select all

    IDNAME = Format(Now, "yyyymmddhhnnss")
because that would make it easy to sort the IDNAME values.
TKS!
I choose the second, because is a good tips! :cheers:

User avatar
SpeakEasy
4StarLounger
Posts: 544
Joined: 27 Jun 2021, 10:46

Re: create a unique id with year, month, day, hh,mm,ss

Post by SpeakEasy »

Of course, you need to make sure that at least 1 second has elapsed between ID assignments ...