


How to Convert DateTime to VarChar in SQL Server Without the Time Component?
Convert DateTime to VarChar (without time part) in SQL Server
To convert a DateTime variable to a VarChar variable in yyyy-mm-dd format, you can use the built-in CONVERT function:
CONVERT(VARCHAR(10), GETDATE(), 120) /* 将 'GETDATE()' 替换为您的 DateTime 变量 */
This command will return the VarChar value in the specified yyyy-mm-dd format, excluding the time part.
Other styles for converting DateTime to VarChar
In addition to the 120 style, a number of other styles can be used to format output VarChar values. The following demo illustrates the various styles and their corresponding output:
DECLARE @now DATETIME SET @now = GETDATE() SELECT CONVERT(VARCHAR(MAX), @now, style) AS output, style FROM ( SELECT 0 AS style UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 10 UNION SELECT 11 UNION SELECT 12 UNION SELECT 13 UNION SELECT 14 UNION SELECT 120 UNION SELECT 121 UNION SELECT 126 UNION SELECT 127 UNION SELECT 130 UNION SELECT 131 ) AS Styles ORDER BY style;
Output:
输出 | 样式 |
---|---|
Apr 28 2014 9:31AM | 0 |
04/28/14 | 1 |
14.04.28 | 2 |
28/04/14 | 3 |
28.04.14 | 4 |
28-04-14 | 5 |
28 Apr 14 | 6 |
Apr 28, 14 | 7 |
09:31:28 | 8 |
Apr 28 2014 9:31:28:580AM | 9 |
04-28-14 | 10 |
14/04/28 | 11 |
140428 | 12 |
28 Apr 2014 09:31:28:580 | 13 |
09:31:28:580 | 14 |
2014-04-28 09:31:28.580 | 120 |
2014-04-28 09:31:28.580 | 121 |
2014-04-28T09:31:28.580 | 126 |
2014-04-28T09:31:28.580 | 127 |
28/06/1435 9:31:28:580AM | 130 |
28 جمادى الثانية 1435 9:31:28:580AM | 131 |
Note that the output format can be adjusted by selecting the appropriate style parameters for the CONVERT function.
The above is the detailed content of How to Convert DateTime to VarChar in SQL Server Without the Time Component?. For more information, please follow other related articles on the PHP Chinese website!

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

WebStorm Mac version
Useful JavaScript development tools
