SQL Server gives you two functions for formatting values: FORMAT() and CONVERT(). They overlap enough that it’s not always obvious which one to reach for. This article skips the feature-by-feature breakdown and focuses on answering the question of which one you should use for a given scenario.
DBMS
Database Management Systems
SQL Server DATE_FORMAT() Equivalent: How to Format Dates in SQL Server
If you’ve come from MySQL and you’re trying to use DATE_FORMAT() in SQL Server, you’ve already hit the problem: it doesn’t exist. SQL Server has no DATE_FORMAT() function. The good news is it has two functions that do the same job, and in some cases do it better.
How to Filter by Today’s Date in SQL Server (And the Mistake Most Beginners Make)
Filtering records by today’s date sounds simple enough, but there’s a gotcha that’s easy to miss if you’re not careful. This article starts with the correct approach, then explains why the obvious method fails. So you’ll know what to do and why.
SQL Server CONVERT() Date Style Codes Explained (With Examples)
In SQL Server, dates are stored in one format but often need to be displayed in another. That’s where the CONVERT() function can help. It lets you take a date value and turn it into a string in whatever format you need, whether that’s MM/DD/YYYY for an American audience or DD-MM-YYYY for a universally recognized date format.
The tricky part when using this function is the style code. This a number you pass into CONVERT() that tells it which format to use. There are dozens of style codes, and they’re not exactly intuitive to memorise. This article breaks down the most useful ones with real examples so you can find what you need and move on.
How to Convert a Date to a String in SQL Server
There are a few reasons you might need to convert a date to a string in SQL Server. Maybe you need a date in a specific format for a report. Maybe you’re concatenating it with other text. Maybe an external system expects dates as strings. Whatever the reason, SQL Server gives you several ways to do it, and the right one depends on what you’re trying to achieve.
This article covers four functions: FORMAT(), CONVERT(), CAST(), and STR().
What Is a Knowledge Graph Database?
A knowledge graph database stores information as a network of connected entities rather than rows and columns. Instead of asking “what data do we have?”, it asks “how does this data relate to everything else?” That shift in thinking is what makes it useful in situations where traditional databases start to struggle.
How to Compare Performance Across Different Query Plans in SQL Server
When a query has multiple execution plans in Query Store, comparing their performance can help you identify which plan performs best and understand why performance may have regressed. This comparison can be very useful for troubleshooting queries that suddenly became slower after a plan change.
Fix Error 155 “‘DAYS’ is not a recognized dateadd option” in SQL Server
If you’re getting an error that reads something like “‘DAYS’ is not a recognized dateadd option” in SQL Server, it’s because you’re using the DATEADD() function with an invalid datepart argument.
This often happens when you use a plural form of the argument. For example, DAYS instead of DAY. Or HOURS instead of HOUR.
The easiest way to fix this is to provide a valid datepart argument.
How to Get the Current Date in SQL Server
SQL Server has several functions that return the current date and time. If you just need today’s date for a query, that sounds like it should be simple. And it is. But there are six different functions to choose from, and they don’t all return the same thing. This article explains what each one does and when to use it.