Results 1 to 9 of 9
  1. #1
    didiomm is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Dec 2013
    Posts
    47

    Question Convert dates to more conventional format

    Hi All:

    I've inherited data that has to be put in a DB that has dates saved as texts and dates in yyyy-mm-dd hh:mm:sss formats.



    For example, one dataset has this date saved as text: '4122016' which equals April 12, 2016. How do I convert this to the 8 digit format ("mm-dd-yyyy"?) Because eventually the dataset will jump up to 8 digits by virtue of October dates having to be inputted.

    I would like to convert yyyy-mm-dd hh:mm:sss into an 8 digit date format as well.

    I tried select left for the long format, but I need more parsing to get it to the 8 digit format and nothing I've tried has worked so far.

    Any help would be appreciated!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can use a combination of the Left(), Right() and Mid() functions along with DateSerial(), but you have to be very sure of the data. What if it was "1162016"; is that Jan 16 or Nov 6? Are days always input as 2 digits?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    didiomm is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Dec 2013
    Posts
    47
    Hi pbaldy:

    Given the historical format for any dates that are the 1st of the month through the 9th of the month are always marked as

    "01","02","03","04","05","06","07","08", and "09"

    I have to assume that when January rolls around again that the date 1012017 is truly January 1, 2017 and 11012016 is truly November 1, 2016.
    So when using the Left, Mid, and Right syntax would I add in the "0" for months 1(January) through 9(September)?

    For example: 1012016 would be converted to 01-01-2016, but how do I code this date to dateserial and not just a string?

    And how do I build in the dateserial syntax.

    Regarding parsing the long date using Left, Mid, Right syntax, I tried this:

    Code:
    SELECT MID(qryPaymentPostedDate.PostedDate,6,5) &"-"&LEFT(qryPaymentPostedDate.PostedDate,4)
    FROM qryPaymentPostedDate
    It works great (thanks)! Again, is there a certain syntax to use to wrap the dateserial function around the above code to code it as a date?

    Thanks for your help
    Last edited by didiomm; 06-22-2016 at 07:28 AM. Reason: tried to clarify my mumbo jumbo

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Along the lines of:

    DateSerial(Right(...), Left(...), Mid(...))
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    didiomm is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Dec 2013
    Posts
    47
    I tried this

    Code:
    DateSerial(Mid([qryPaymentPostedDate].[PostedDate],6,5),&( "-" &),(LEFT([qryPaymentPostedDate].[PostedDate],4)), AS Expr1
    but I keep getting "wrong number of arguments" error

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Well, the function has 3 arguments: year, month and day.

    https://support.office.com/en-us/art...a-93f2b046f503
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    didiomm is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Dec 2013
    Posts
    47
    Still getting errors: could it be that the "Right ()" function needs to have some kind of trimming to exclude the hh:mm:ss.mis data? Because it seems that my query to modify the date with the suggested syntax

    Code:
    (SELECT DateSerial(Right(qryPaymentPostedDate.PostedDate,15),Left(qryPaymentPostedDate.PostedDate,4),Mid(qryPaymentPostedDate.PostedDate,6,2)) AS Expr1
    FROM qryPaymentPostedDate;
    is turning my date into this: 04-05-2016 00:00:00.000 instead of the mm-dd-yyyy I needed. I say "seems" because the resultset is nothing but #Error all the way to the end of the list.

    Thanks for your help, pbaldy.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Well, if the data still looks like '4122016', your numbers don't make any sense. You'd want the right 4 for year, not 15.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    didiomm is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Dec 2013
    Posts
    47
    Thanks pbaldy. but the code I most recently posted about is for the dataset with the long format, not the dateset with the shorter format. Sorry for the confusion. I'm waist-deep in wading through this so you can imagine my confusion as well

    If there were a way to format the results of my code in my second post (and reposted below) into being a date instead of text then I would be done, already!

    Code:
    SELECT MID(qryPaymentPostedDate.PostedDate,6,5) &"-"&LEFT(qryPaymentPostedDate.PostedDate,4)
    FROM qryPaymentPostedDate

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

Similar Threads

  1. How to Convert Dates Over To Months
    By djclinton15 in forum Queries
    Replies: 2
    Last Post: 11-08-2015, 07:34 PM
  2. Replies: 1
    Last Post: 03-18-2015, 09:17 AM
  3. Format Does Not Convert Check Box value
    By CementCarver in forum Reports
    Replies: 2
    Last Post: 04-23-2013, 02:19 PM
  4. Replies: 4
    Last Post: 03-12-2013, 06:49 PM
  5. Convert seconds to HH:MM:SS format
    By sai_rlaf in forum Access
    Replies: 2
    Last Post: 01-19-2012, 12:57 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