This topic is locked

Default value for a filed as numerical value of date/time

6/24/2009 6:11:04 PM
ASPRunnerPro General questions
M
mfred author

I need to have the default value in a field be unigue numbers. I was thinking that it would be good if there was a way to set the default value of a field to be a numerical expression of the date/time. Any ideas for this or anyway to have a field generate a number when the add page loads would be much appreciated.

Sergey Kornilov admin 6/24/2009

Try something like this:

year(now()) & Month(now()) & Day(now()) & hour(now()) & minute(now()) & second(now())
S
stalbone 6/25/2009

I need to have the default value in a field be unigue numbers. I was thinking that it would be good if there was a way to set the default value of a field to be a numerical expression of the date/time. Any ideas for this or anyway to have a field generate a number when the add page loads would be much appreciated.


You can also use recommended getdate() function instead of now() which is not a part of T-SQL.

M
mfred author 6/25/2009

That worked nicely. Thanks.

C
clig 6/25/2009

I need to have the default value in a field be unigue numbers. I was thinking that it would be good if there was a way to set the default value of a field to be a numerical expression of the date/time. Any ideas for this or anyway to have a field generate a number when the add page loads would be much appreciated.


you could also mimic "time_t" for something unique:
DATEDIFF(s, "Jan 01 1970", Now())
then flip it back and forth as a reference - accounting for GMT (if your NOW() was GMT) - so for an EST:
DATEADD(s,time_t_column - 18000, "1/1/1970")) * there is 18000 seconds in 5 hours but I have seen 18400 used in previous calculations...