Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2006
    Location
    DC
    Posts
    123

    Unanswered: DTS / VBScript Date format

    Hey guys,
    I have a database import that I'm doing and I'm using DTS/VBscript to manipulate data.

    I created a varchar field to import a date in the following format 030906.
    Does anyone have a suggestion on making it 03/09/06?
    Or just the best way to handle this type of data

    thanks,

    Jonathan

  2. #2
    Join Date
    Jun 2004
    Location
    Long Island
    Posts
    696
    Quote Originally Posted by jdmarsh2g
    Hey guys,
    I have a database import that I'm doing and I'm using DTS/VBscript to manipulate data.

    I created a varchar field to import a date in the following format 030906.
    Does anyone have a suggestion on making it 03/09/06?
    Or just the best way to handle this type of data

    thanks,

    Jonathan
    parsdate(Date)

    VBScript:
    Function ParseDate(sDate)
    Dim sYear, sMonth, sDay
    Dim sFormatDate

    sYear = Mid( sDate, 1, 2)
    sMonth = Mid( sDate, 3, 2)
    sDay = Mid( sDate, 5, 2)

    sFormatDate = sMonth & "/" & sDay & "/" & sYear
    ParseDate = sFormatDate
    End Function

  3. #3
    Join Date
    Jun 2006
    Location
    DC
    Posts
    123
    Perfect thank you so much ....
    I appreciate it

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    The best way is to use the appropriate datatype to store the date, not fudge it into a varchar column.
    George
    Home | Blog

  5. #5
    Join Date
    Jun 2004
    Location
    Long Island
    Posts
    696

    Thumbs up

    Quote Originally Posted by PMASchmed
    parsdate(Date)

    VBScript:
    Function ParseDate(sDate)
    Dim sYear, sMonth, sDay
    Dim sFormatDate

    sYear = Mid( sDate, 1, 2)
    sMonth = Mid( sDate, 3, 2)
    sDay = Mid( sDate, 5, 2)

    sFormatDate = sMonth & "/" & sDay & "/" & sYear
    ParseDate = sFormatDate
    End Function
    Correction, according to your date layout should be

    sMonth = Mid( sDate, 1, 2)
    sDay = Mid( sDate, 3, 2)
    sYear = Mid( sDate, 5, 2)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •