Os.date("%m") returning 7 not 07?

Hello, I am trying to format the date so that it looks like 29/07/2021 but when I do the this

local Date = string.format("%u/%u/%u", os.date("%d"), os.date("%m"), os.date("%Y"))
print(Date)

It returns 29/7/2021, does anyone know why this is happening as os.date("%m") on it’s own returns 07?

Do this

local Date = table.concat({os.date("%d"), os.date("%m"), os.date("%Y")}, "/")
print(Date)         -- 29/07/2021
2 Likes

The 0 at the start of the number gets dropped whenever you use %u to convert to a signed number. 01 becomes 1, 02 becomes 2, etc.

os.date("%m") on its own returns 07 because you aren’t converting it into a signed number with your formatting rules.

image


You can just do os.date("%d/%m/%Y") by the way.

2 Likes