search
HomeComputer TutorialsComputer KnowledgeQuestions about inserting time in SQL database

Questions about inserting time in SQL database

Jan 17, 2024 pm 01:18 PM
sql time function

Questions about inserting time in SQL database

Insertion time problem in sql database

CONVERT(varchar(10), getDate(),120)

Convert the time format into character format (10) Note that this is very important, and then insert it

CONVERT(nvarchar(10),count_time,121): CONVERT is a date conversion function, usually in the time type

The function used to convert between (datetime, smalldatetime) and string types (nchar, nvarchar, char, varchar) has three parameters. The first parameter refers to the size after conversion, the second parameter refers to the field or function that needs to convert the date, and the third parameter refers to the format of the conversion.

0 | 0 or 100 | mon dd yyyy hh:miAM (or PM)

1 | 101 | mm/dd/yy

2 | 102 | yy-mm-dd

3 | 103 | dd/mm/yy

4 | 104 | dd-mm-yy

5 | 105 | dd-mm-yy

6 | 106 | dd mon yy

7 | 107 | mon dd,yy

8 | 108 | hh:mm:ss

9 | 9 or 109 | mon dd yyyy hh:mi:ss:mmmmAM (or PM)

10 | 110 | mm-dd-yy

11 | 111 | yy/mm/dd

12 | 112 | yymmdd

11| 13 or 113 | dd mon yyyy hh:mi:ss:mmm(24-hour format)

14 | 114 | hh:mi:ss:mmm(24-hour format)

15 | 20 or 120 | yyyy-mm-dd hh:mi:ss(24-hour format)

16 | 21 or 121 | yyyy-mm-dd hh:mi:ss:mmm(24-hour format)

How to calculate the execution time of sql statement

The datediff function is generally used in SQL to represent the time difference.

Basic syntax:

DATEDIFF(datepart,startdate,enddate)

illustrate:

The startdate and enddate parameters are legal date expressions.

The datepart parameter can be the following values:

example:

Example 1

Use the following SELECT statement:

SELECT DATEDIFF(day,'2008-12-29','2008-12-30') AS DiffDate

result:

DiffDate

1

Example 2

Use the following SELECT statement:

SELECT DATEDIFF(day,'2008-12-30','2008-12-29') AS DiffDate

result:

DiffDate

-1

The above is the detailed content of Questions about inserting time in SQL database. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:Excel办公网. If there is any infringement, please contact admin@php.cn delete
How to Remove the SecureBootEncodeUEFI.exe Trojan?How to Remove the SecureBootEncodeUEFI.exe Trojan?Apr 13, 2025 am 12:50 AM

Some Windows 11/10 users report that they see a cmd window open up right after a Bitdefender update and it is running SecureBootEncodeUEFI.exe. This post from php.cn introduces how to remove the SecureBootEncodeUEFI.exe Trojan.

Fix: Sysdll_win64_retail.dll Missing or Not Found Error - MiniToolFix: Sysdll_win64_retail.dll Missing or Not Found Error - MiniToolApr 13, 2025 am 12:48 AM

Sysdll_win64_retail.dll is a dynamic link library (DLL) file related to the FIFA 17 application. When that file gets missed or corrupted, a series of issues and errors will happen about that application. To resolve this issue, you can read this artic

Is Core Isolation Blocked by ew_usbccgpfilter.sys? Here Are Fixes!Is Core Isolation Blocked by ew_usbccgpfilter.sys? Here Are Fixes!Apr 13, 2025 am 12:47 AM

Many SurfaceBook users report that they meet the “core isolation blocked by ew_usbccgpfilter.sys” issue on Windows 11/10. This post from php.cn helps to fix the annoying issue. Keep on your reading.

How to Remove Options from the Ctrl   Alt   Del Screen?How to Remove Options from the Ctrl Alt Del Screen?Apr 13, 2025 am 12:46 AM

When you press Ctrl Alt Del on your computer, you will enter the Security Options window, where you might see Lock, Switch user, and Sign out options. Do you know that these options can be changed? This php.cn post will show you how to remove opt

How to Remove Virus:Win32/Grenam.VA!MSR? Here Is a Guide!How to Remove Virus:Win32/Grenam.VA!MSR? Here Is a Guide!Apr 13, 2025 am 12:45 AM

Some Windows 11/10 users report that their Windows Defender has spotted a virus named Virus:Win32/Grenam.VA!MSR. But they don’t know how to remove it. This post from php.cn teaches you how to remove Virus:Win32/Grenam.VA!MSR.

How to Save a Website as a Desktop App?How to Save a Website as a Desktop App?Apr 13, 2025 am 12:44 AM

When you need to visit a website frequently, it is quite troublesome to open a browser and search for it every time. Why don’t you try to save a website as an app? If you do this, you can open it as normal software. Here, php.cn offers you some usefu

A Full Guide to Fixing the Windows Update Error 0x00000000A Full Guide to Fixing the Windows Update Error 0x00000000Apr 13, 2025 am 12:43 AM

Some people encountered the error code 0x00000000 on Windows 11 when they installed the latest Windows update. What should you do to cope with this unexpected error? This article on the php.cn Website will give you some clues for troubleshooting.

How to Fix FileType Selected Not Supported by This AppHow to Fix FileType Selected Not Supported by This AppApr 13, 2025 am 12:41 AM

Are you suffering from the error message "FileType selected not supported by this app" when opening files in Teams or Excel? Now read this post from php.cn to get several useful solutions to this issue.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools