79672196

Date: 2025-06-19 14:17:20
Score: 1.5
Natty:
Report link

I recently had to deal with something similar and thought I’d share how I approached it — I’m still learning SQL, so I used dbForge Studio for SQL Server to help me figure it out visually.

My original date looked like 'JAN-01-2025', and I needed to convert it into yyyymmdd format (like 20250101). Since that format isn’t directly supported, I ended up doing two things:

  1. Replaced the hyphens with spaces, because style 107 (which parses dates like "Jan 01 2025") needs that.

  2. Then I used TRY_CONVERT to safely turn the string into a proper DATE.

  3. And finally, I formatted it as char(8) using style 112 to get the yyyymmdd.

SELECT 
  OriginalValue = val,
  ConvertedDate = CONVERT(char(8), TRY_CONVERT(date, REPLACE(val, '-', ' '), 107), 112)
FROM (VALUES ('JAN-01-2025'), ('FEB-30-2025')) AS v(val);


Reasons:
  • Blacklisted phrase (1): help me
  • Blacklisted phrase (0.5): I need
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Samantha Brauer