Photo by Steve Johnson on Unsplash
Hello, coders! ๐ป
How about a quick little challenge?
How would you left pad zeros to month and day parts of this stringified date 2022-5-3 so that we get 2022-05-03?
๐ More info on the official doc
Click for a solution using PHP
$input = '2022-5-3';
$output = vsprintf('%04d-%02d-%02d', explode('-', $input));
vsprintf takes an array as input so we do that using explode and then we specify the output format.
Happy coding! โจ๏ธ
Top comments (1)
I just added a quick solution using PHP.
Let's see your answers using other languages!