web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Day name mismatch

(0) ShareShare
ReportReport
Posted on by 2,172

Hello all,

I want to display the day name with respect to the date selected, for that i used the below example. But when i run this job, its showing day name as"Thurs day" instead of "Monday". Could you please explain, why it is showing like that...!

public void sampledate()
{

DateOnhand   d;
;

d = today();

info(strfmt("Date - %1",d));

info(strfmt("Day Name - %1",dayname(dayOfMth(d))));

}

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Sohaib Cheema Profile Picture
    49,664 Super User 2026 Season 1 on at

    have you tried dayOfWk() as under:-

    date d = today();

       int i;

       ;

       i = dayOfWk(d);

       info("Today's day of the week is " + dayName(i));

    Note that it would take value form your local date time of session

  • Anand AX Profile Picture
    2,172 on at

    Hi Sohaib Cheema,

    Thanks for reply, Your code is working fine. Thank you, but why the above code(mine) is showing today as thursday, Is there any reason behind?

  • Verified answer
    Sohaib Cheema Profile Picture
    49,664 Super User 2026 Season 1 on at

    it  because of definition of dayName Function

    it will not care how you are giving it value. it will take only value. Today as date is 18-JAN-2016, so it calculates it like following

    18 = 7+7+4

    7 = Make Count from zero

    7 = again make count from 0

    4 = Monday, Tuesday, Wed, Thursday

    That's the reason, it gives you wrong result

  • Anand AX Profile Picture
    2,172 on at

    Hi Sohaib Cheema,

    Thank you so much for clear explanation.

  • Bashir Ahmad Profile Picture
    5,248 on at

    You can get Name of the Day by passing the day number as param:

       and use something like that :

    public DueDate  getWeekStartDate(DueDate _Date)
    {
      str       nameOfDay;
      int    i;
      DueDate      StartDateofWeek =_Date ;
            i      = dayOfWk( _date);
        nameOfDay = dayName (i);
    
      switch (nameOfDay)
      {
        case enum2str(WeekDays::Saturday):
                //todo
                break;
    
        case enum2str(WeekDays::Sunday):
                //todo
                break;
              
        case enum2str(WeekDays::Monday):
               //todo
                break;);
               
    
        case enum2str(WeekDays::Tuesday):
                 //todo
                break;);
    
          case enum2str(WeekDays::Wednesday):
                 //todo
                break;
    
          case enum2str(WeekDays::Thursday):
             //todo
             break;
          case enum2str(WeekDays::Friday):
           
                break;
    
          default:
                break;
      }
       return DateofWeek;
    
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 24

#2
Michel ROY Profile Picture

Michel ROY 14

#3
Jagadabi Profile Picture

Jagadabi 6

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans