+ Reply to Thread
Results 1 to 12 of 12
  1. #1
    Registered User
    Join Date
    01-31-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    12

    Sort datetime values

    Hi

    There is a column in my excel file which contains data in date time format : dd.yyyy hh:mm:ss:sss .z format, I want to sort my file based on this column value, but have not been successful so far.

    01.20.2010 02:38:09:855 PM GMT+05:30
    01.20.2010 02:38:09:855 PM GMT+05:30
    01.20.2010 02:38:09:872 PM GMT+05:30
    01.20.2010 11:52:52:444 AM GMT+05:30
    01.20.2010 11:52:56:560 AM GMT+05:30
    01.20.2010 11:52:57:569 AM GMT+05:30
    01.20.2010 11:52:58:292 AM GMT+05:30
    01.20.2010 11:52:59:139 AM GMT+05:30
    01.20.2010 11:53:02:512 AM GMT+05:30
    01.20.2010 12:07:56:998 PM GMT+05:30
    01.20.2010 12:07:57:822 PM GMT+05:30
    01.20.2010 12:07:58:606 PM GMT+05:30
    01.20.2010 12:07:59:377 PM GMT+05:30

    I searched through few forum entries, where they have advised breaking this into different fields for date and time and then sorting

    Is there a way by which the data can be sorted in the same column without breaking in distinct fields.

  2. #2
    Forum Moderator Richard Buttrey's Avatar
    Join Date
    02-15-2008
    Location
    Grappenhall, UK
    MS-Off Ver
    Excel for Windows & Mac - all versions.
    Posts
    5,826

    Re: Need help with sorting datetime value

    Hi,

    Into which order are you wanting to sort it?

    Rgds
    Richard Buttrey

    If this was useful then please rate it appropriately.

    Click the small star icon at the bottom left of my post.

  3. #3
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Need help with sorting datetime value

    Given AM/PM you will need to convert the strings to date time values in order to sort.

    If we assume your default date format is dd mm rather than mm dd then perhaps you could use:

    Code:
    B1: =--(MID(A1,4,2)&"-"&REPLACE(SUBSTITUTE(SUBSTITUTE(LEFT(A1,26),".","-"),":",".",3),4,3,""))
    copied down
    to generate the time based values -- against which you can apply the sort.

  4. #4
    Registered User
    Join Date
    01-31-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Need help with sorting datetime value

    I have a CSV file that contains data in JAVA SimpleDateFormat as listed above, This is one of the column in the file, and I need to use this date field for generating some dynamic charts (excel OFFSET)

    I require my column to be sorted in ascending order.

    I tried formatting the column to date/Time/Custom types.. but it didnt help
    Last edited by s1joshi; 01-31-2010 at 12:19 PM.

  5. #5
    Registered User
    Join Date
    01-31-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Need help with sorting datetime value

    I tried the formula given above, and this will convert my date format to

    20-01-2010 12:08:02.761 PM
    20-01-2010 12:07:59.377 PM
    20-01-2010 12:07:58.606 PM
    20-01-2010 12:07:57.822 PM
    20-01-2010 12:07:56.998 PM
    20-01-2010 11:53:02.512 AM
    20-01-2010 11:52:59.139 AM
    20-01-2010 11:52:58.292 AM
    20-01-2010 11:52:57.569 AM
    20-01-2010 11:52:56.560 AM
    20-01-2010 11:52:52.444 AM
    20-01-2010 02:38:09.872 PM
    20-01-2010 02:38:09.855 PM
    20-01-2010 02:38:09.855 PM
    20-01-2010 02:38:09.044 PM
    20-01-2010 02:38:06.791 PM
    20-01-2010 02:38:06.785 PM
    20-01-2010 02:38:06.278 PM
    20-01-2010 02:38:06.272 PM

    But when I try to sort my spreadsheet on this column, The data doesnt seem to be sorted
    (AM values in between PM for the same date)

  6. #6
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,131

    Re: Sort datetime values

    Maybe =LEFT(SUBSTITUTE(A1, ".", "-"), 19) + MID(A1, 21, 3)/86400000 + ISNUMBER(FIND(" PM ", A1))/2

    Ignores the GMT offset.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Sort datetime values

    The formula provided previously converts the Time correctly (if your standard date format is day month rather than month day)
    EDIT: shg's will work only if the opposite is true (ie month day standard format)

    The AM/PM in your resulting values is down to the format you have applied to the data.

    If I sort the values you list in your prior post (ie formulae results) they are listed in order as expected - ie for me they are numerics - we're assuming the same is true for you (ie no #VALUE! output)

    Like shg's formula the earlier formula assumes the GMT offset is consistent, ie is ignored.

    If you need further assistance post a file.
    Last edited by DonkeyOte; 01-31-2010 at 02:40 PM.

  8. #8
    Registered User
    Join Date
    01-31-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Sort datetime values

    Hi

    Can you please have a look -
    Attached Files Attached Files

  9. #9
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Sort datetime values

    I would suggest perhaps trying the actual formula provided earlier...

    Note specifically those characters that appear post equals sign in my formula but that are missing in yours.

  10. #10
    Registered User
    Join Date
    01-31-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Sort datetime values

    Really appreciate your quick response, time and effort in helping me on the issue , actually I was getting an error with the two sign's, Can you elaborate on the formula or point me to some link, which I can refer to understand the process of converting string to excel date format

    If you dont mind can you share your worksheet
    Last edited by s1joshi; 01-31-2010 at 04:10 PM.

  11. #11
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Sort datetime values

    If you get a #VALUE! error then the implication is that your default date format is in fact month day year rather than day month year, in which case try either shg's version or:

    Code:
    B2: =--SUBSTITUTE(SUBSTITUTE(LEFT(A2,26),".","-"),":",".",3)
    If the above also returns #VALUE! then try:

    Code:
    B2: =--SUBSTITUTE(LEFT(A2,26),":",".",3)
    If neither of the above work you will need to detail your default date format.
    ie - if you enter a datetime value into a cell in what format are you entering it ?

  12. #12
    Registered User
    Join Date
    01-31-2010
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Sort datetime values

    Thanks so much for your assistance in helping with the issue.

Thread Information

Users Browsing this Thread

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

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.2.0