Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Transforming and verifying dates

Transforming and verifying dates

Scheduled Pinned Locked Moved Database
databasehelpquestion
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Johnny 0
    wrote on last edited by
    #1

    I am probabely be called an idiot rom now on but I can't figure this out, tried everything. Here I have to trasfer in SQL a very disfunctionnal FMP database. This is the function that verifies the dates. The problem I have is this: It works perfectly when the original date (formatted 01/01/1800) is correct but the last part should overwrite any malformed date (anyways that was the intention....) but none get overwritten. I always get the malformed date back. It is as if @DateTest never gets put to False. Help!!:confused: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER FUNCTION [dbo].[GetBirthDate] ( @BirthDate nvarchar(10) ) RETURNS nvarchar(10) AS BEGIN DECLARE @ReturnValue nvarchar(10) DECLARE @DateTest bit SET @DateTest = 'True' IF (@BirthDate = '00/00/00' OR @BirthDate = '' OR @BirthDate = '?' OR @BirthDate IS NULL) SET @ReturnValue = '1800-01-01' ELSE BEGIN IF LEN(@BirthDate) = 10 SET @ReturnValue = SUBSTRING(@BirthDate, 7, 4) + '-' + SUBSTRING(@BirthDate, 4, 2) + '-' + LEFT(@BirthDate, 2) ELSE SET @ReturnValue = '19' + SUBSTRING(@BirthDate, 7, 2) + '-' + SUBSTRING(@BirthDate, 4, 2) + '-' + LEFT(@BirthDate, 2) END IF (SUBSTRING(@ReturnValue, 1, 2) <> '19' AND SUBSTRING(@ReturnValue, 1, 2) <> '20') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 3, 1) < '0' OR SUBSTRING(@ReturnValue, 3, 2) > '9') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 4, 1) < '0' OR SUBSTRING(@ReturnValue, 4, 2) > '9') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 6, 1) < '0' OR SUBSTRING(@ReturnValue, 6, 2) > '1') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 7, 1) < '0' OR SUBSTRING(@ReturnValue, 7, 2) > '9') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 9, 1) < '0' OR SUBSTRING(@ReturnValue, 9, 2) > '3') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 10, 1) < '0' OR SUBSTRING(@ReturnValue, 10, 2) > '9') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 5, 1) <> '-') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 8, 1) <> '-') SET @DateTest = 'False' IF @DateTest = 'False' SET @ReturnValue = '1800-01-01' RETURN @ReturnValue END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO

    J 1 Reply Last reply
    0
    • J Johnny 0

      I am probabely be called an idiot rom now on but I can't figure this out, tried everything. Here I have to trasfer in SQL a very disfunctionnal FMP database. This is the function that verifies the dates. The problem I have is this: It works perfectly when the original date (formatted 01/01/1800) is correct but the last part should overwrite any malformed date (anyways that was the intention....) but none get overwritten. I always get the malformed date back. It is as if @DateTest never gets put to False. Help!!:confused: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER FUNCTION [dbo].[GetBirthDate] ( @BirthDate nvarchar(10) ) RETURNS nvarchar(10) AS BEGIN DECLARE @ReturnValue nvarchar(10) DECLARE @DateTest bit SET @DateTest = 'True' IF (@BirthDate = '00/00/00' OR @BirthDate = '' OR @BirthDate = '?' OR @BirthDate IS NULL) SET @ReturnValue = '1800-01-01' ELSE BEGIN IF LEN(@BirthDate) = 10 SET @ReturnValue = SUBSTRING(@BirthDate, 7, 4) + '-' + SUBSTRING(@BirthDate, 4, 2) + '-' + LEFT(@BirthDate, 2) ELSE SET @ReturnValue = '19' + SUBSTRING(@BirthDate, 7, 2) + '-' + SUBSTRING(@BirthDate, 4, 2) + '-' + LEFT(@BirthDate, 2) END IF (SUBSTRING(@ReturnValue, 1, 2) <> '19' AND SUBSTRING(@ReturnValue, 1, 2) <> '20') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 3, 1) < '0' OR SUBSTRING(@ReturnValue, 3, 2) > '9') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 4, 1) < '0' OR SUBSTRING(@ReturnValue, 4, 2) > '9') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 6, 1) < '0' OR SUBSTRING(@ReturnValue, 6, 2) > '1') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 7, 1) < '0' OR SUBSTRING(@ReturnValue, 7, 2) > '9') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 9, 1) < '0' OR SUBSTRING(@ReturnValue, 9, 2) > '3') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 10, 1) < '0' OR SUBSTRING(@ReturnValue, 10, 2) > '9') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 5, 1) <> '-') SET @DateTest = 'False' IF (SUBSTRING(@ReturnValue, 8, 1) <> '-') SET @DateTest = 'False' IF @DateTest = 'False' SET @ReturnValue = '1800-01-01' RETURN @ReturnValue END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO

      J Offline
      J Offline
      Johnny 0
      wrote on last edited by
      #2

      I had to answer to this one myself, this is too funny. My stored procedure was calling another function I wrote that had a similar name :omg: It was a pleasure wasting everybody's time ! :rolleyes:;P

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups