Solved

Save data from form as datetime

Posted on 2011-09-12
3
286 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
3 Comments
 
LVL 32

Assisted Solution

by:ewangoya
ewangoya earned 62 total points
Comment Utility

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
Comment Utility
Thanks ewangoya,
Anyway, i'll explore the idea.
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 63 total points
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now