Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Getting Correct Day Of Month
Started by akhtarx5 Apr 30 2019 05:09 PM

- - - - -
2 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

akhtarx5

[GLOBAL: userInfoPane.html]
akhtarx5
  • Enthusiast

  • 70 posts
  • Corona SDK

HI

 

im trying to obtain the date in 1 day from now.

 

so if today is 30 April 2019 (you will need to change your date to 30 April 2019 manually)

 

what is the correct way to achieve this

im using this code but using +1 gives 32 as answer rather than 1 , April Being 30 days only.

 

t = os.date("*t")
t.day = t.day + 1
position = os.time(t)

print ("Monthday= "..t.day)

 

 



[TOPIC: post.html]
#2

Alan PlantPot

[GLOBAL: userInfoPane.html]
Alan PlantPot
  • Contributor

  • 917 posts
  • Corona SDK

I would probably do this:

local tomorrowsDate = os.date("*t", os.time() + 86400)
print("month = "..tomorrowsDate.month)
print("day = "..tomorrowsDate.day)

If you provide a unix timestamp as the second argument to os.date() it returns the date for that timestamp rather than the current time.

 

Likewise, if you don't pass any arguments to os.time() it automatically returns the current unix time. So I just add one day's worth of seconds on (86400 seconds), and then pass that as the second argument to the os.date() function. 



[TOPIC: post.html]
#3

akhtarx5

[GLOBAL: userInfoPane.html]
akhtarx5
  • Enthusiast

  • 70 posts
  • Corona SDK

Brilliant , Thanks So Much...


[topic_controls]
[/topic_controls]