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
 Development Tools
 ASP.NET
 sql server datefield

Author  Topic 

kirannatt
Yak Posting Veteran

66 Posts

Posted - 2004-07-21 : 13:14:50
Hi everyone,

I am developing asp.net(c#) application. I need to validate date format. sqlserver stores date in diferent format but user enters date in format mm/dd/yyyy. I need to authenticate user by date.

also wondering how can we get datefield value from sqlserver.


please help me out.

thanks,
kiran

kselvia
Aged Yak Warrior

526 Posts

Posted - 2004-07-21 : 13:20:52
To validate a date:

SET DATEFORMAT MDY; SELECT IsDate('01-30-2004')

To get the current date:

SELECT getdate()


--Ken
Your Kung-Fu is not strong. -- 'The Core'
Go to Top of Page

kirannatt
Yak Posting Veteran

66 Posts

Posted - 2004-07-21 : 13:38:20
Hi Ken,

I tried to change dateformat by this query SET DATEFORMAT MDY but sqlserver still stores date in format yyyy-mm-dd.

thanks for ur help
kiran
Go to Top of Page

kselvia
Aged Yak Warrior

526 Posts

Posted - 2004-07-21 : 13:49:18
SQL stores dates as a binary value representing a time offset from Jan 1 1800, or something like that. You can not change how it stores dates. The application is usually responsible for formatting dates. You can convert dates to varchar and output a variety of date formatting. See CONVERT in Books Online for a list of the various formats you can use.


--Ken
Your Kung-Fu is not strong. -- 'The Core'
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2004-07-21 : 15:43:25
You could use a Regular Expression validator or a Compare Validator to validate the date on the client or server side. I belive this is the perfered way of doing things in .Net. Well, that's how I perfer to do them anyway.

Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>
Go to Top of Page
   

- Advertisement -