Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Enforce Date format in SQL

Author  Topic 

ashishashish
Constraint Violating Yak Guru

408 Posts

Posted - 2012-03-20 : 00:58:57
how can i enforce user to insert date only in "yyyy-mm-dd hh:mm:ss" format.

I understand that i can convert date anytime in any format using "CONVERT" function. But i like user to enter date in this format.

OR

How can i check if the format of entered date in database is correct or not. I like to use some function which check dates.

Thanks in Advance

------------------------------------------------
The answer is always no till than you don't ask.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-03-20 : 01:47:18
You can easily do this in the front end application

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-20 : 01:52:19
Insert into WHERE/WHAT

And you really want them to insert the seconds?

Do you want the exact datetiem that a record is being updated or inserted? If yes, you can do that with a default of GetDate()


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-20 : 15:24:12
quote:
Originally posted by ashishashish

how can i enforce user to insert date only in "yyyy-mm-dd hh:mm:ss" format.

I understand that i can convert date anytime in any format using "CONVERT" function. But i like user to enter date in this format.

OR

How can i check if the format of entered date in database is correct or not. I like to use some function which check dates.

Thanks in Advance

------------------------------------------------
The answer is always no till than you don't ask.


why do need to do this?
so far as datatype is datetime and you're passing the values in unambiguos format like YYYYMMDD it shouldnt cause any issues. while retrieving you can change it to any format you want using dateformatting functions

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -