Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Using os.date and os.time

edited September 2014 in General Posts: 142

I am trying to take the hour and minute in the day and assign a value to a variable according to the time of day. As of right now I am recording the time as follows.

time = os.date("%I"..":".."%M".." ".."%p")

Obviously I can't compare a string to a number i.e. If os.date("%I") > 8 then , so I was wondering how I could accomplish my goal. Also, I'm a little confused in how os.time works so I thought I'd throw that in here for anyone who would like to explain it to me.

Comments

  • Jmv38Jmv38 Mod
    Posts: 3,297

    this kind of basic question are easy to find with google. try it. First link:
    http://stackoverflow.com/questions/9560142/lua-date-format-and-comparison

  • Posts: 142

    @Jmv I know it is pretty basic, but I did look it up on google first and 1. I couldn't find anything specifically aimed at my question (this wasn't exactly what I was going for, but after re-reading the page a couple of times, I think I know what to do now) and 2. I thought it would be good to start a thread on it in codea so people could just search the forum as that's where I usually look first.

  • dave1707dave1707 Mod
    Posts: 8,496

    @Staples Here's an example of using os.date. The for loop shows the variables that are returned. The other print statements show how to use them individually.


    function setup() d=os.date("*t") for a,b in pairs(d) do print(a,b) end print() print("the hour is ",d.hour) print("the minute is ",d.min) end
  • edited September 2014 Posts: 1,976

    You can compare a string to a number if the string contains just a number. Try using tonumber(os.date("%l"))

  • edited September 2014 Posts: 142

    @dave1707 @SkyTheCoder Thanks, I've figured out how to do what I was trying to do!

Sign In or Register to comment.