Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 638911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:47:03+00:00 2026-05-13T20:47:03+00:00

We have a function that pulls the date from the first 8 characters of

  • 0

We have a function that pulls the date from the first 8 characters of a string. Because of the way this system was written, the users are told they have to enter the date in an 8 character format in the field. For example, 12/06/10 must be entered. The way the original function was written, 12/6/10 or 12/06/2010 would generate a wrong date.

I modified the function to the code below to correct this issue and wonder if anyone has any other suggestions to make this more bullet proof. I’m assuming that returning the datetime will always return a valid date for both 19xx or 20xx. I’m not sure what SQL uses to determine when to use 19xx vs. 20xx and I’m not worried about dates less that 1980 and greater than 2100.

We are still on SQL Server 2000 for this app.

Alter FUNCTION [dbo].[GetDateFromField] ( @FieldString varchar(256) )   
RETURNS datetime AS

BEGIN

    DECLARE @tempResult varchar(8)

    SET @tempResult =  left(@FieldString,8)

    IF isdate(@tempResult) = 0
    BEGIN
        SET @tempResult = NULL
    END

    RETURN @tempResult

END
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:47:03+00:00Added an answer on May 13, 2026 at 8:47 pm

    The “century cut-off” date is controlled by a SQL Server setting – check out this blog post for a great explanation.

    Execute this to see your current setting:

    sp_configure 'show advanced options', 1
    RECONFIGURE
    
    sp_configure 'two digit year cutoff'
    

    You can also change this option as needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that pulls rows from a database, the content->id and content->type
I have a form text field that pulls a date from a database (in
I have a function that pulls articles records from an MSSQL database. Some are
So I have function that formats a date to coerce to given enum DateType{CURRENT,
In my Java code I have function that gets file from the client in
I have a function that takes an input string and then runs the string
I have a php page that pulls data from a mysql database based on
I have a function that pulls data out of an XML file. I am
I'm building a jquery function that pulls from a database in order to allow
I have an html table that pulls data from a DB. It has an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.