Skip to main content

Does K2 have a function that enables one to get the numeric value of a weekday, as in .Net?  For example, 0 for Sunday, 1 for Monday.....6 for Saturday...

Hi cjmoran

 

Not out of the box, but there is a Weekday inline function that converts a date to the actual day name (e.g. Tuesday) rather than an integer.  You could try and convert that result to the integer you need using rules or an expression.


Hello,


 


There is no out of the box feature to do a conversion from day of the week to a numeric value. Such as an operator to be used in an expression that does the conversion. However there are a few ways to do this using a combination of K2 and other technologies such as SQL, a Web Service, or a SmartBox SmartObject.


 


You could try and create a SmartBox smart object that contains an ID, the days of the week, and a number. Then run your day against the smartbox smartobject, if the day you have input matches a day in the smartbox then it should return the number relevant. This concept also applies to creating a SQL table, same exact strategy, you will just need to create a service instance to the SQL server and then make a smart object off of the table.


 


Since you are familiar with .NET its possible to also do this through creating a WCF web service and then setting up a service instance off of this. You would need some sort of backend source to tie a day of the week to a number for this. Although you may already have code based on your previous knowledge.


 


You can also create an expression to do this but it would be quite lengthy if you are trying to incorporate the evaluation of all days. Not as easy as writing this out in code would be with a simple method that takes in a date or day of the week as a string, converts to int based on a day and returns that int you so desire. I have done a quick test for an expression based on one day. See attached .png file. Today's date represents the day to be replaced and in this case it is only looking for if it is monday. 


 


-Evan


 


 


 


12267i178F781373022CBA.png

@cjmoran,


 


I am not sure where your value is coming from and in what form, but I tried to put something togther with a drop down list as a makeshift data dictionary. 


Essentially I built a static dropdown list with numeric values, ,0-6] and displayed the days sSunday-Saturday]


I transferred data from a text box to the drop down list, then transferred data from the drop down list to a data label. 


I did it for both numeric input and text input. 


 


15070iCA28BD32E2AABEEE.jpg


 


 


 


 


Dear , 

 

There is no direct way to do that as i beleive , But as was said before in previous posts , u could use WeekDay to workarround this ,

Not rly sure where ur input come from and where ur output goes , but ive tried it in simple scenario here and it worked 

 

first i added calendar for input and text box for output , 

 

14695iC9397EE9AE0C8E16.png

 

Note: i have done that for Sunday and Monday only , if this is the approach u wanna use , u will need to complete the expression for the rest of week days.

 

Hope it helps ,

Best regards.


Reply