Results 1 to 12 of 12
  1. #1
    nkuebelbeck is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    91

    number to Date format

    I have a number field which has date information in it. ex - 20110112 YYYYMMDD in that format. Don't ask why they didn't just make it a date format.....

    Right now a date conversion table is used. So when referencing that field it does a join on the number date and return the date format. Two field table. First column is 'number date format' and the second is 'return date format'. The table is manually kept up each year.



    anywho,

    Just trying to figure out how to format that into a Date format so that I can perform date function on it using sql so that I don't have to maintain the date conversion table.

    thanks!

  2. #2
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    You can create a date from it in a query by using:

    MyDate:DateSerial(Left([OriginalDate],4), Mid([OriginalDate], 5, 2), Right([OriginalDate], 2))

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Only way I can get it to work is:

    CDate(Left(fieldname,4) & "/" & Mid(fieldname,5,2) & "/" & Right(fieldname,2))

    EDIT: I was composing reply as Bob posted! I like DateSerial, have to remember that one.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    nkuebelbeck is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    91

    clarification

    Trying to implement and I'm not sure If I follow what your sql is doing(i'm not and sql wiz by any stretch of the imagination)

    I'm getting a syntax error.....

    Here is my sql(download being my table and promise date being the field)

    Download.[Promise Date]ateSerial(Left([OriginalDate],4), Mid([OriginalDate], 5, 2), Right([OriginalDate], 2))

  5. #5
    nkuebelbeck is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    91
    NVM I figured it out. Much appreciated!

  6. #6
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    You should have in the query (QBE Grid under FIELD):

    PrDate:DateSerial(Left([Promise Date], 4), Mid([Promise Date], 5, 2), Right([Promise Date]))

    And this would yield a field named PrDate.

  7. #7
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by nkuebelbeck View Post
    NVM I figured it out. Much appreciated!
    NP - I went and answered before I saw you had it.

  8. #8
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by June7 View Post
    I like DateSerial, have to remember that one.
    DateSerial is extremly handy and is much easier to use than CDate many times but not only that but it is helpful when trying to get the last day of the month. By using

    DateSerial(Year(Date()), Month(Date()), 0)

    You can get the last day of last month. If you used 1 instead of 0 it wold give the current month's first day, but by simply using 0 instead, you can get the previous end of month.

  9. #9
    nkuebelbeck is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    91
    All is not well. Turns out it was never working my bad

    To clarify I am using Access 2010 32bit.

    I enter in
    PrDateateSerial(Left([Promise Date], 4), Mid([Promise Date], 5, 2), Right([Promise Date]))

    Into the QBE field

    As soon as I exit the field in error pops up

    "The expression you entered has a function containing the wrong number of arguments"

    Thanks in advance!

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Missing the length argument for Right()

    DateSerial(Left([Promise Date], 4), Mid([Promise Date], 5, 2), Right([Promise Date], 2))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    nkuebelbeck is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    91
    THANKS! I should have caught that.

    +1

  12. #12
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by nkuebelbeck View Post
    THANKS! I should have caught that.

    +1
    So should I have caught it.


Please reply to this thread with any new information or opinions.

Similar Threads

  1. Number format in queries
    By bullwinkle55423 in forum Queries
    Replies: 1
    Last Post: 08-16-2011, 06:55 PM
  2. Conditional number format
    By terryvanduzee in forum Forms
    Replies: 1
    Last Post: 07-14-2011, 01:29 AM
  3. Ordinal Number Format
    By injanib in forum Forms
    Replies: 2
    Last Post: 06-15-2011, 01:55 PM
  4. Default number format?
    By joewilly1 in forum Queries
    Replies: 1
    Last Post: 11-24-2010, 09:57 AM
  5. Phone number format
    By ManvinderKaur in forum Access
    Replies: 1
    Last Post: 06-24-2010, 08:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums