+ Reply to Thread
Results 1 to 18 of 18

Different date format in a data query

  1. #1
    Registered User
    Join Date
    06-02-2022
    Location
    Copenhagen, Denmark
    MS-Off Ver
    365
    Posts
    9

    Question Different date format in a data query

    Hi,

    I have to draw data til excel to assess status on accidents.
    The data arrives from one source, but depending on who entered the data on the individual accident the date format is different (depending on whether they have an English or Danish Office 365 ).

    In one row it is written as [4/27/2022 2:52pm] and in another it is written as [19-05-2022 14:22].
    I cannot format the cells to a uniform date format, and I was told I could use IF/IFS to create a uniform date for further excel calculations, e.g. I need to know the number of dates between accident date and registration date.
    This is not doable as the date format is not the same for the two cells.

    Any ideas on how to solve this riddle?
    Thank you in advance,
    Louise

  2. #2
    Valued Forum Contributor
    Join Date
    11-22-2014
    Location
    Arizona, USA
    MS-Off Ver
    Office 365
    Posts
    973

    Re: Different date format in a data query

    Is there other data in conjunction with the dates?

    Ideally you have an identifier to indicate where the date was originated that way you can call out the right value...

    IF - the formats stick to what you have shown above... in which the date is MM/DD/YYYY and DD-MM-YYYY then an IF will do just fine...

    Is this in a cell alone or is there more data in it?
    Please Login or Register  to view this content.
    You would need to update all the A1 References to what you want
    -If you think you are done, Start over - ELeGault

  3. #3
    Registered User
    Join Date
    06-02-2022
    Location
    Copenhagen, Denmark
    MS-Off Ver
    365
    Posts
    9

    Re: Different date format in a data query

    Data in the row consist of an ID number, accident type, date of accident, date of creating the registration, etc. Each data point have a cell.
    Ie the date (and timestamp) is in a cell on its own: Format 1 [4/27/2022 2:52 PM], format 2 [19-05-2022 14:42] and I just need [03-06-2022].

    When I try to enter your formula into my spreadsheet it tells me there is a problem with the formula...?
    When you write A1 reference does that refer to my date I want changed?

    Apologies for sounding daft, I've never tried to discuss excell stuff before and I've just taught myself to use basic IFS and CountIFS. This is a new language to me =)

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,410

    Re: Different date format in a data query

    Welcome to the forum.

    For your locale, you will need to change ALL commas to semi-colons:

    =HVIS.FEJL(DATO(HØJRE(VENSTRE(A1;FIND(" ";A1)-1);4);HØJRE(VENSTRE(A1;FIND("-";A1;FIND("-";A1)+1)-1);2);UDSKIFT(HØJRE(VENSTRE(A1;FIND("-";A1)-1);2);"[";""));DATO(HØJRE(VENSTRE(A1;FIND(" ";A1)-1);4);UDSKIFT(HØJRE(VENSTRE(A1;FIND("/";A1)-1);2);"[";"");HØJRE(VENSTRE(A1;FIND("/";A1;FIND("/";A1)+1)-1);2)))

    If that doesn't work, then there are instructions at the top of the page explaining how to attach your sample workbook.

    A good sample workbook has just 10-20 rows of representative data that has been desensitised. It also has expected results mocked up, relevant cells highlighted and a few explanatory notes.
    Last edited by AliGW; 06-03-2022 at 04:39 AM.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  5. #5
    Registered User
    Join Date
    06-02-2022
    Location
    Copenhagen, Denmark
    MS-Off Ver
    365
    Posts
    9

    Re: Different date format in a data query

    Thank you Elegault and AliGW =) (Not sure how to tag both of you)

    Now I think I understand the situation. I didn't consider the , vs ; issue. I'll give it a new try and if my limited excel skills still come up short I'll do representative data insert.
    Last edited by AliGW; 06-07-2022 at 12:49 PM. Reason: PLEASE don't quote unnecessarily!

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,410

    Re: Different date format in a data query

    Glad to have helped.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  7. #7
    Registered User
    Join Date
    06-02-2022
    Location
    Copenhagen, Denmark
    MS-Off Ver
    365
    Posts
    9

    Re: Different date format in a data query

    Hi AliGW, thank you the formula works better now (English text and ; ), but it comes up with a #NAME? - not sure why. I've attached a sample worksheet with my data now.
    Column J has the various date formats and column K the attempt at a corrected date with a uniform format.

    Thanks again and thank you for being patient with me
    Attached Files Attached Files
    Last edited by LouisePeder; 06-09-2022 at 06:37 AM.

  8. #8
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,704

    Re: Different date format in a data query

    When I open the file the first part of the formula is shown as:

    =IF.error ...

    This should be:

    =IFERROR ...

    i.e. there is no full-stop. That gives rise to the #NAME error.

    In addition, though, you have #REF errors in the formula - I think you must have deleted some rows and columns in order to get this smaller sample file, and in doing so you have messed up the cell references.

    The final 2 formulae do have cell references, however, but these point to S87 and S88, and there is no data in those cells - should these point to column J cells ?

    Hope this helps.

    Pete

  9. #9
    Registered User
    Join Date
    06-02-2022
    Location
    Copenhagen, Denmark
    MS-Off Ver
    365
    Posts
    9

    Re: Different date format in a data query

    Thank you Pete_UK :D I've removed the full-stop and now it comes up as #value! ?

    And yes I have deleted quite a few rows and columns so as to no show any sensitive material and in that swoop made errors in other columns... They work in my original spreadsheet so hopefully that is ok when I return to it to remove the full-stop

  10. #10
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,147

    Re: Different date format in a data query

    VBA solution
    Please Login or Register  to view this content.
    in K2

    =corrdate([@[Case closed date]])

    copy down
    Attached Files Attached Files
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  11. #11
    Valued Forum Contributor
    Join Date
    11-22-2014
    Location
    Arizona, USA
    MS-Off Ver
    Office 365
    Posts
    973

    Re: Different date format in a data query

    Oh this is much simpler... I thought the brackets you previously used to describe your data was in fact the part of the format.

    Just put =DATEVALUE([@[Case closed date]]) as your Date Corrected Column and format to the view/format you wish to utilize. No need for a bunch of extras as fun as it all is

  12. #12
    Registered User
    Join Date
    06-02-2022
    Location
    Copenhagen, Denmark
    MS-Off Ver
    365
    Posts
    9

    Re: Different date format in a data query

    To JohnTopley: I've written the formula in K2 and I've added the Developer tool to my ribbon and clicked VBA and then I'm not sure what to do and where to write your solution?
    Last edited by LouisePeder; 06-10-2022 at 04:20 AM.

  13. #13
    Registered User
    Join Date
    06-02-2022
    Location
    Copenhagen, Denmark
    MS-Off Ver
    365
    Posts
    9

    Re: Different date format in a data query

    To ELeGault:
    Tried that now and it gives me some corrected dates now
    Not all the dates are corrected and some are written wrong ie 6/7/2022 (7th June) is written as 06-07-2022 (6th July).

    Maybe I'm in over my head ...?

  14. #14
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,147

    Re: Different date format in a data query

    to insert VBA code:

    Click on "Developer" >> "Visual Basic"

    Click "Insert">> "Module" which will initiate a blank area on the right of the screen

    Copy/Paste code into this area then Close window

  15. #15
    Registered User
    Join Date
    06-02-2022
    Location
    Copenhagen, Denmark
    MS-Off Ver
    365
    Posts
    9

    Re: Different date format in a data query

    You are amazing JohnTopley Thank you so much!

    Thank you to all of you for helping me! - and for being patient with my excel skills.
    Last edited by AliGW; 06-10-2022 at 06:04 AM. Reason: PLEASE don't quote unnecessarily!

  16. #16
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,410

    Re: Different date format in a data query

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, if you have not already done so, you may not be aware that you can thank those who have helped you by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of all those who offered help.

  17. #17
    Registered User
    Join Date
    06-02-2022
    Location
    Copenhagen, Denmark
    MS-Off Ver
    365
    Posts
    9

    Re: Different date format in a data query

    Done and Done
    Thanks again Ali!
    Last edited by AliGW; 06-10-2022 at 06:16 AM. Reason: PLEASE don't quote unnecessarily!

  18. #18
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,410

    Re: Different date format in a data query

    Administrative Note:

    Please don't quote whole posts, especially when you are responding to the one immediately preceding your own - it's just clutter. It's OK to quote if you are responding to a post out of sequence, but limit quoted content to a few relevant lines that makes clear to whom and what you are responding. Thanks!

    For normal conversational replies, try using the QUICK REPLY box below or the REPLY button instead of REPLY WITH QUOTE.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How to query by date format yyyy-mm-dd?
    By AccountingJ in forum Access Tables & Databases
    Replies: 4
    Last Post: 05-14-2020, 12:14 PM
  2. [SOLVED] power query date format
    By orhanceliloglu in forum Excel General
    Replies: 3
    Last Post: 06-18-2018, 08:08 AM
  3. [SOLVED] Date format in query
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-05-2015, 06:05 AM
  4. Date format problem from an BI query
    By ruangeld in forum Excel General
    Replies: 7
    Last Post: 07-07-2012, 08:10 AM
  5. Date query - conditional format
    By conks in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-16-2010, 05:13 PM
  6. MS Query Date Format
    By scos00 in forum Excel General
    Replies: 1
    Last Post: 03-03-2010, 04:34 PM
  7. [SOLVED] Date format - ADO query Access to Excel
    By gocush in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-24-2005, 06:07 AM

Tags for this Thread

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