പ്രോഗ്രാമിംഗ് ഭാഷ അനുസരിച്ച് തീയതി ഫോർമാറ്റുകൾ

തീയതി ഫോർമാറ്റിംഗിനുള്ള കോഡ് ഉദാഹരണങ്ങൾ

ഭാഷ തിരഞ്ഞെടുക്കുക

ദ്രുത റഫറൻസ്: YYYY-MM-DD

പ്രശസ്ത ഭാഷകളിൽ YYYY-MM-DD (ISO 8601) ആയി തീയതി ഫോർമാറ്റ് ചെയ്യുന്നത് ഇങ്ങനെ:

💛 JavaScript
const date = new Date(); // Method 1: toISOString (recommended) const formatted = date.toISOString().split('T')[0]; console.log(formatted); // Output: 2025-12-31 // Method 2: Manual formatting const yyyy = date.getFullYear(); const mm = String(date.getMonth() + 1).padStart(2, '0'); const dd = String(date.getDate()).padStart(2, '0'); console.log(`${yyyy}-${mm}-${dd}`); // Output: 2025-12-31
🐍 Python
from datetime import datetime date = datetime.now() formatted = date.strftime('%Y-%m-%d') print(formatted) # Output: 2025-12-31
🐘 PHP
<?php echo date('Y-m-d'); // Output: 2025-12-31
🐬 MySQL
SELECT DATE_FORMAT(NOW(), '%Y-%m-%d') AS formatted_date; -- Output: 2025-12-31

സാധാരണ ഫോർമാറ്റ് കോഡുകൾ

വ്യത്യസ്ത ഭാഷകൾ വ്യത്യസ്ത ഫോർമാറ്റ് കോഡുകൾ ഉപയോഗിക്കുന്നു.

അർഥം Python/PHP JavaScript SQL
വർഷം (4 അക്കങ്ങൾ) %Y getFullYear() %Y / YYYY
വർഷം (2 അക്കങ്ങൾ) %y manual %y / YY
മാസം (01-12) %m getMonth()+1 %m / MM
മാസ പേര് %B toLocaleDateString() %M / Month
ദിവസം (01-31) %d getDate() %d / DD

ഫോർമാറ്റ് അനുസരിച്ച് ബ്രൗസ് ചെയ്യുക

തീയതി ഫോർമാറ്റിംഗിനുള്ള നുറുങ്ങുകൾ

മികച്ച പ്രാക്ടീസ്: ഡാറ്റാബേസുകളിൽ തീയതികൾ സംഭരിക്കുമ്പോൾ, എല്ലായ്പ്പോഴും ISO 8601 (YYYY-MM-DD) ഫോർമാറ്റ് ഉപയോഗിക്കുക.
സമയമേഖല നുറുങ്ങ്: സമയമേഖല വ്യത്യാസങ്ങളെക്കുറിച്ച് ശ്രദ്ധിക്കുക.