+ Reply to Thread
Results 1 to 3 of 3

Sort age with dateif formula - no leading zeros

  1. #1
    Registered User
    Join Date
    03-04-2013
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    1

    Sort age with dateif formula - no leading zeros

    The following works well with working out age to give age in years and months (eg 9 y 10 m)

    =DATEDIF(birthday,date,"y") & " y " & DATEDIF(birthday,date,"m")-12*DATEDIF(birthday,date,"y") & " m"

    My problem is trying to sort this column. Doing a straight sort goes by year then month
    1 y 10 m
    1 y 2 m
    10 y 10 m
    10 y 2 m
    2y 10m and so on

    Is there a way to format to give leading zeros so that the sort works the way I want it to?
    Otherwise I may have to resort to writing a macro which will be tedious!

    Thanks

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,937

    Re: Sort age with dateif formula - no leading zeros

    In a helper column (it could be hidden if necesary), do a datedif formula with the difference in days. Sort this column.

    Alan
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,481

    Re: Sort age with dateif formula - no leading zeros

    A little bit shorter:
    =DATEDIF(birthday,date,"y")&" y "&DATEDIF(birthday,date,"ym")&" m"
    Have you tried to sort with date column?
    Quang PT

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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