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!