0

I have a choice column in which choices are name of months. I want a calculated column which returns me the date format data.

Choice Column  |  Calculated Column  
-----------------------------------  
January        |  1-Jan-1990  
February       |  1-Feb-1990  
March          |  1-Mar-1990  
April          |  1-Apr-1990  
May            |  1-May-1990  

Date and year can be anything but I want to sort this data month wise. If I use choice column to sort data it will sort it alphabetically. But I want to sort the data in Month wise.

Is there any formula that can convert my choice column value to date format.

I tried to use below formula but it did not worked.

=DATE(YEAR(1990),MONTH([Month]),DAY(1))

Month is the choice column.

Is there any other way? I have to use Choice column I don't have any other option.

Or is there any way using which I can use Date Time column type in which user only selects month?

Any suggestions will be appreciated.

2 Answers 2

2

You can do it by jslink.

  1. Make one js file (ex. ViewMonth.js) and add following code:

Replace your column name instead of MonthNum and month

(function () 
{
    var monthctx = {};
    monthctx.Templates = {};
    monthctx.Templates.Fields = {

        "MonthNum": {
            "View": setmonth
        }
    };
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(monthctx);
})();

//Note: 0=January, 1=February etc
function setmonth(ctx) 
{
     var itemID = ctx.CurrentItem.ID;
    var date = new Date("1-" + ctx.CurrentItem["month"] + "-1999"); 
   return date.getMonth();
}
  1. Upload js file to document library.

  2. Edit list page and edit webpart property.

  3. Add js server relative path with specific prefix

    ~sitecollection/Shared Documents/ViewMonth.js

  4. You can get month number in specified column and now you can sort with it.

1
=MONTH( "January" )

will not return a value because SharePoint doesn't have a clue what you meant

You have to convert the Month TEXT to a valid Number (january=1 in SharePoint)

IF([column]="January" , 1 , [column]="Feb2" , 2 , ...
2
  • Is there any other way, using which I can sort Choice column value date wise? In C# using code? Commented Apr 6, 2016 at 20:51
  • With c# you can program anything you want. this is a SharePoint forum, not c# Commented Apr 7, 2016 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.