Convert MM/YYYY to YYYY-MM
01/2025 → 2025-01
Quick Converter
→
2025-01
How to Convert MM/YYYY to YYYY-MM
Converting from MM/YYYY to YYYY-MM involves rearranging the date components:
From
MM/YYYY
01/2025
to
YYYY-MM
2025-01
1
Identify the Parts
In MM/YYYY: Month-year format commonly used for credit cards, expiration dates, and monthly reports
2
Rearrange
Reorder to match YYYY-MM format: Year-month format following ISO 8601, ideal for file naming and sorting
3
Adjust Separator
Change the separator from "/" to "-" if needed.
Code Examples
JavaScript
// Convert MM/YYYY to YYYY-MM
function convertDate(dateStr) {
// Parse MM/YYYY
const parts = dateStr.split('/');
const [year, month, day] = parts;
// Format as YYYY-MM
return `${year}-${month}-${day}`;
}
console.log(convertDate('01/2025')); // 2025-01
Python
from datetime import datetime
# Convert MM/YYYY to YYYY-MM
date_str = '01/2025'
date = datetime.strptime(date_str, '%Y-%m-%d')
result = date.strftime('%Y-%m-%d')
print(result) # 2025-01