How to format a date in a query to switch the digits

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anoble1
    New Member
    • Jul 2008
    • 246

    How to format a date in a query to switch the digits

    Right now when I run my query the default date reads: 20140519

    I would like it to read: 05/19/2014
    Is that possible? thanks,
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3653

    #2
    anoble,

    Is your "date" a Date data type or is it a Text data type.

    There are several places to start, of which
    Code:
    CDate()
    function could probably transform your "text" date into a date data type. Then it is just an issue of format, which would be easily solved by the
    Code:
    Format()
    function.

    In your case:

    Code:
    Format(CDate([YourDateString]),"mm/dd/yyyy")
    Hope this helps.

    Comment

    • anoble1
      New Member
      • Jul 2008
      • 246

      #3
      Here is what I have: "BD_BDT" is the Field name. Table name is "QS36F_MNBD D"

      I tired this below. But got a data type mismatch
      Code:
      Expr1: CDate([BD_BDT])
      Also tried:
      Code:
      Expr1: Format(CDate([BD_BDT]),"mm/dd/yyyy")

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        anoble1:
        Open your table in design view.
        Select the field that contains your data.
        In that row, their is a column titled: "Data Type:
        Please tell us what datatypecast is shown there.

        Comment

        • anoble1
          New Member
          • Jul 2008
          • 246

          #5
          Data Type is Number. This is a linked table

          Comment

          • twinnyfo
            Recognized Expert Moderator Specialist
            • Nov 2011
            • 3653

            #6
            So, your "date" is actually the "number" 20,140,519?

            Then, I would recommend converting to Text (using CStr() Function).

            But this is really not your problem. Although "20140519" looks like a date it is actually completely different, so, unless you want to convert this value every time you encounter it, you should probably look into getting the original data converted to a Date format.

            Sooooooooo..... ........ this might work:

            Code:
            Format(CDate(Left(CStr(20140519),4) & "-" & Mid(CStr(20140519),5,2) & "-" & Right(CStr(20140519),2)),"mm/dd/yyyy")
            But it is a kinda silly way to do it. But it works.
            Last edited by zmbd; Aug 25 '14, 06:39 PM. Reason: [z{bingo}]

            Comment

            • anoble1
              New Member
              • Jul 2008
              • 246

              #7
              Yes, that worked great. Good idea about switching the Main data source.

              Comment

              • twinnyfo
                Recognized Expert Moderator Specialist
                • Nov 2011
                • 3653

                #8
                Glad I could help! Hope you have a great day!

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32633

                  #9
                  You could try (for the date value) :
                  Code:
                  CDate(Format(lngDateVal,"0000\/00\/00"))
                  This assumes your date is stored in lngDateVal in the format specified.

                  Comment

                  Working...