Skip to main content
Back to problems
#3280
Easy Algorithms

Convert date to binary

Math String
88.7% acceptance
Feb 25, 2026
158
11
You are given a string date representing a Gregorian calendar date in the yyyy-mm-dd format. date can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in year-month-day format. Return the binary representation of date.

Solution

Rust
Time O(1)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn convert_date_to_binary(date: String) -> String {
    let parts: Vec<&str> = date.split('-').collect();
    let year: u32 = parts[0].parse().unwrap();
    let month: u32 = parts[1].parse().unwrap();
    let day: u32 = parts[2].parse().unwrap();
    format!("{:b}-{:b}-{:b}", year, month, day)
  }
}