Solved

Save data from form as datetime

Posted on 2011-09-12
3
291 Views
Last Modified: 2012-05-12
Hello Experts,
I've got a form which has a DOB field (textbox) ...my potential problem is that when a user does not supply the correct format i'm having a problem saving the data. For example...
If the user supplies '1/1/91' i'm getting an out of range error since the stored proc which does the saving of data

CONVERT(DATETIME, @DOB, 121) as DOB

Is there any way of saving the data without experiencing the errors.
0
Comment
Question by:jsuanque
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 62 total points
ID: 36526513

Put validation code in your stored procedure. if the date has a two digit year value, you decide how to correct it or reject it

There are several functions you can use

ISDATE() to verify the string is a proper date

The you could something of the sort

IF YEAR(@DOB) < 100
  IF YEAR(@DOB) + 2000 > YEAR(GETDATE())
    set it to 19XX
  else
    set it to 20xx
 
0
 

Author Comment

by:jsuanque
ID: 36526751
Thanks ewangoya,
Anyway, i'll explore the idea.
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 63 total points
ID: 36526786
You need to validate the date in the presentation layer (i.e. in your "form which has a DOB field").  By the time it gets to the Stored Procedure it is too late.

Incidentally, you are using the wrong style for '1/1/91'.  121 is ODBC canonical (with milliseconds) yyyy-mm-dd hh:mi:ss.mmm(24h)

What you need for '1/1/91' is depending on your date format:
MDY: CONVERT(DATETIME, @DOB, 1) as DOB
DMY: CONVERT(DATETIME, @DOB, 3) as DOB




 
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question