Monday 13 May 2013

Month function in Lua for QlikView Expressor

Lua doesn't have a Dual data type like QlikView's.  However, it does have a native Table data type that could allow us to simulate a Dual.  At the end of the day, you are still going to have to the different values as separate outputs, but it could be useful to have a simple function that will give you one or the other.

Here you go:

function month(vdate)

   rval = nil
   -- Set up a table of Month names
   local months = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}

   if is.datetime(vdate) then
      -- Get the month number using datetime.moment
      local monthnum = datetime.moment(vdate, "m")
      -- Return a table of the Text and Num values
      rval = {Text = months[monthnum], Num = monthnum}

   return rval


This would be called something like this:

d = string.datetime("20130513", "CCYYMMDD")

print (month(d).Text, month(d).Num)


Stephen Redmond is CTO of CapricornVentis a QlikView Elite Partner. We are always looking for the right people to join our team.
Follow me on Twitter: @stephencredmond

No comments:

Post a Comment

Note: only a member of this blog may post a comment.