+ Reply to Thread
Results 1 to 3 of 3

Converting fields to date in design view

Hybrid View

  1. #1
    Registered User
    Join Date
    03-01-2007
    Posts
    37

    Converting fields to date in design view

    I need to convert data that looks like this 08162008 it's formated as text and needs to look like this 08/16/2008 there are multiple dates and years within this field.

  2. #2
    Forum Contributor GuruWannaB's Avatar
    Join Date
    01-24-2008
    Location
    An hour due East of Cowtown Ohio
    MS-Off Ver
    2010
    Posts
    421

    Re: Converting fields to date in design view

    Try this - where a1 has your text format date data.

    =DATE(RIGHT(A1,4),LEFT(A1,2),mid(a1,3,2))
    Last edited by GuruWannaB; 03-19-2009 at 12:07 PM. Reason: condensed formula part of left(right(a1,6),2) to mid(a1,3,2)
    I help because of the Pavlovian dog that resides in the inner me...so if you are happy with the results, please add to my reputation. It helps keep me motivated!



    Please mark your threads as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Administrator ExlGuru's Avatar
    Join Date
    03-17-2009
    Location
    India
    MS-Off Ver
    2003,2007
    Posts
    222

    Re: Converting fields to date in design view

    Try this:

    Public Function TextBoxDateFormat(DAscii As Integer, DTBox As TextBox)
        
        'Set error trapping on
         On Error GoTo ErrorHandler
         
        'Inserts '/' into date
         TextBoxDateFormat = DAscii
        
        'Check code
         If IsNumeric(Chr(DAscii)) Then
             
             'Format
              If ((Len(DTBox.Text) = 2) Or (Len(DTBox.Text) = 5)) And (IsNumeric(Chr(DAscii))) Then
                      
                  'Add a /
                   DTBox.Text = DTBox.Text + "/"
                   DTBox.SelStart = Len(DTBox.Text)
              
              ElseIf Len(DTBox.Text) = 7 Then
                  
                  'Format
                   DTBox.Text = Format(DTBox + Chr(DAscii), "dd/mm/yyyy")
                   TextBoxDateFormat = 0
                   DTBox.SelStart = 10
              End If
         
         ElseIf DAscii <> 8 Then
         
             'Do not allow the keystroke
              TextBoxDateFormat = 0
         End If
        
        'Exit
         Exit Function
         
    ErrorHandler:
        
        'Process error
         'WriteToErrorLog "ModHelperRoutines", "TextBoxDateFormat", Err.Number, Err.Description
         Resume Next
    
    End Function
    ExlGuru

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1