Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validating Date Parameter in SQL Server Stored Procedure

I've written a stored procedure that takes in a date parameter. My concern is that there will be confusion between American and British date formats. What is the best way to ensure that there is no ambiguity between dates such as 02/12/2008. One possibility would be for users to enter a date in a format such as 20081202 (yyyymmdd). Is there any way to validate that without using sub strings? Alternatively dates could be entered as 02-Dec-2008(dd-mmm-yyyy), but again verification is not trivial and there are potential issues with users who do not use English.

Further to the first three answers . . . One issue is that I'm expecting this stored proc to be called directly without a front end so validation ouside of the proc is not an option. Is it a good idea to take the day, month and year as separate parameters?

like image 710
macleojw Avatar asked Mar 23 '26 01:03

macleojw


1 Answers

You won't have any problems whatsoever if you'd use parameters in your sproc:

create proc dbo.Sproc
    @date datetime
as
    ...
like image 115
Anton Gogolev Avatar answered Mar 25 '26 18:03

Anton Gogolev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!