[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

convert a General Date into an ID

I need to convert a General Date (3/25/2004 3:16:34 PM) into a string or Intiger to be used as
an ID ei: 325200431634

I have tried a couple different things but nothing works....any ideas?
the Date is stored in the field "Date_and_Time_Of_Occurance"
1 Solution
use the format command

sID = Format(myDate,"MMDDYYYYNNMMSS")
sorry, that should be HHNNSS not NNMMSS

When just an ID is needed, simply change the date into a number field. :-)

It will have decimals for the hours/minutes/sec part, but an update query with * 100000 can "remove" that when needed.

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

You can simply manually change the data type of your field to double or single type. The result slightly reminds a date but you'll get an ID field. Also that field easely converts back to Full Date.
Sebastian_cAuthor Commented:
Thats works great! BUT when I use Date, it gives a number 03262004000000
What happened to the HHMMSS?
BTY You get the points rockiroads!
Sebastian_cAuthor Commented:
How do I declair General Date in the eqation:

sID = Format(myDate,"MMDDYYYYNNMMSS")
did your date have a time in it? dump your date you wish to convert

if you look in help on the Format command, there are plenty of types you can change it to

when you mean declare Generate Date in the equation, what do you mean? do you want to return a General Date?

you can use Format(myDate,"General Date")

but basically, format takes any date or date/time and formats it to any style you want (again, see help for otpions)

some examples
Dim MyTime, MyDate, MyStr
MyTime = #17:04:23#
MyDate = #January 27, 1993#

' Returns current system time in the system-defined long time format.
MyStr = Format(Time, "Long Time")

' Returns current system date in the system-defined long date format.
MyStr = Format(Date, "Long Date")

MyStr = Format(MyTime, "h:m:s")    ' Returns "17:4:23".
MyStr = Format(MyTime, "hh:mm:ss AMPM")    ' Returns "05:04:23 PM".
MyStr = Format(MyDate, "dddd, mmm d yyyy")    ' Returns "Wednesday,
    ' Jan 27 1993".
' If format is not supplied, a string is returned.
MyStr = Format(23)    ' Returns "23".

' User-defined formats.
MyStr = Format(5459.4, "##,##0.00")    ' Returns "5,459.40".
MyStr = Format(334.9, "###0.00")    ' Returns "334.90".
MyStr = Format(5, "0.00%")    ' Returns "500.00%".
MyStr = Format("HELLO", "<")    ' Returns "hello".
MyStr = Format("This is it", ">")    ' Returns "THIS IS IT".

Sebastian_cAuthor Commented:
Thank you rocki!
I ended up using: sID = Format(Time, "MMDDYYYYHHMMSS")
which gives me a unique number each time...

ok, just to note, did you lose the leading zero?
if you did and you dont want to lose it, how about putting YYYY first, just a thought


Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now