Date Parts

Send Snippet To: Save this snippet to Code Collector Pro -- view all roger's snippets
language: Other
license: Other

Code for Snippet:

                
-- given a string date of '2006-12-31' breaks it down to integer yy, mm and dd
-- Compatible with Lua 5.0 and 5.1.
-- from sam_lie 
function get_date_parts(date_str)
  local iyy, imm, idd 
 
  if (date_str) then
    x = string.gsub(date_str, "(%d+)-(%d+)-(%d+)", function (yy,mm,dd)    
        iyy = tonumber(yy)
        imm = tonumber(mm)
        idd = tonumber(dd)
      end)
  end
 
  return iyy, imm, idd
end
comments powered by Disqus

Info

Link to this snippet:


Download to Code Collector

To use the direct link to your snippet on CodeCollector.net either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 8
Date Added: 2018-01-09 05:04:38
Last Modified: 2018-01-10 09:54:13

Web Analytics