I have a table that contains records, with a DATETIME column. I am writing a stored proc that will take a startTime and endTime and return all records between these two times. I want to force users to provide the time in a specific format (‘YYYY-MM-DDThh:mm:ss.nnn’). The reason being I don’t my table contains a lot of records, and I don’t want to limit the data retrieval to two points in time during the same day only (so they must provide times to a seconds granularity at least).
Is there anyway to enforce this?
Thanks.
Yes, but then you have to take the parameters as strings (varchar) instead of datetime, as the datetime values
2010-12-08and2010-12-08 00:00:00.000are the same.You can verify that the length of the input strings meet the requirement, and then convert them to datetime using
convert(datetime, startTime, 126).