Questions tagged [datetime2]

A SQL Server type that defines a date that is combined with a time of day that is based on 24-hour clock. datetime2 can be considered as an extension of the existing datetime type that has a larger date range, a larger default fractional precision, and optional user-specified precision.

A SQL Server data type that define a date that is combined with a time of day that is based on a 24-hour clock. datetime2 can be considered as an extension of the existing datetime type that has a larger date range, a larger default fractional precision, and optional user-specified precision.

References and resources

155 questions
0
votes
0 answers

DateTime2 prefixed with "T"

When using Tasks - Generate Scripts... it is now generating the DateTime2 with a Prefix of "T" for the time (example 1) instead of leaving it blank (example 2). How do I remove the Prefix "T" when generating my scripts? Example…
0
votes
1 answer

Error converting data type varchar to datetime. Stored procedure and two functions

Msg 8114, Level 16, State 1, Procedure sp_wl_CalculateWorklistItemGroupTypeCurrentStats, Line 0 [Batch Start Line 619] Error converting data type varchar to datetime. exec sp_wl_CalculateWorklistItemGroupTypeCurrentStats…
0
votes
0 answers

Delphi SQL DateTime2(5) Fraction Truncated

Got one Table with DateTime2(5) field . It looks like this : 2021-09-07 10:54:14.97317 Now I setup FDConnection with one FDQuery . I get the Column back as TSQLTimeStamp. Now I try this : …
user1937012
  • 1,031
  • 11
  • 20
0
votes
1 answer

to_timestamp() in scala returns default timestamp format

I have a dataframe with timestamp in the following format "yyyy-MM-dd HH:mm:ss.SSSSSSS" I want to trim the milliseconds and nanoseconds from the given string and convert that into datetime type. I tried using the to_timestamp() method to convert…
0
votes
1 answer

Error converting varchar to Datetime in a SQL Function

I am trying to create a function that converts a given date string to the desired DateTime format. The code is: Alter function dbo.getDateValue1(@inputdate varchar) returns varchar as begin declare @inputDateTransformed datetime = CAST(@inputdate AS…
qudsif
  • 39
  • 4
0
votes
0 answers

Incorrect syntax near '2021'. (102) using pyodbc to insert a datetime object into a SQL Server database

I am trying to insert the current datetime into a datetime2 type column of a SQL Server table: creationdatetime = datetime.datetime.now() # 2021-11-20 21:35:40.851495 sql = ("INSERT INTO [SCHEMA].[TABLE] (\n" "[CreationDateTime]) \n" …
Anouar
  • 85
  • 5
0
votes
0 answers

Datetime2 displayed differently on 2 computers

I have a problem while using DATETIME2 (SQL Server). The display is not the same on two computers with similar configuration (Windows Server 2012). When I do a simple SELECT, the first computer display "2021-10-13 09:50:00" but the second one…
makiteru53
  • 11
  • 1
0
votes
0 answers

Rounding issue from DateTime to DateTime2 SQL v14.0.1000.169

I am attempting to round DateTime to DateTime2, and I was able to round it down to DateTime is rounding to .157, while DateTime2 is rounding to .157000, but DateTime still does not equal DateTme2 when comparing. This is my code: DECLARE @dt2…
0
votes
2 answers

Convert Excel formula (using Date and subtraction) into T-SQL

I am trying to write this Excel formula into T-SQL (to write a function). Expected output is 0.71944444, but currently my output (using T-SQL) is 24.0000. I am not sure why we have to add a day to same date and subtract the same date. Bottom is a…
Java
  • 1,208
  • 3
  • 15
  • 29
0
votes
1 answer

datetime2 truncate to the last full 30 minute period

I'm trying to create a function that's rounding off to the last completed 30 minute period. My definition of a 30 minute period is every hour and half hour (12, 12:30, 13, 13:30, etc.) So if the time is 22:16 I would like it to truncate to 22:00…
Petter Östergren
  • 973
  • 4
  • 14
  • 27
0
votes
2 answers

SQL datetime2 cannot hold datetime

It seems like that a datetime2, in some cases, cannot hold the value of a datetime value. Is this expected? Notice the last 2 columns. Or is it the conversion corrupts the data? SELECT DATETIMEFROMPARTS (2021, 2, 28, 10, 11, 12, 267), …
Stig
  • 1,974
  • 2
  • 23
  • 50
0
votes
0 answers

Micro Focus COBOL 5 Won't Accept SQL Server Dates

A team of developers are trying to upgrade our COBOL from Micro Focus 4 to 5 - and our date processing keeps throwing exceptions working storage ... 01 WS-CURRENT-TIMESTAMP PIC X(026). ... procedure ... 01434 EXEC SQL …
0
votes
3 answers

Add/Select mulitiple columns in SQL based on another column's value condition

I am using SQL Server. Here is the scenario: Let say I have a tableA: UserId UserName TransactionType TransactionDateTime 1 Staff1 NULL NULL 2 Staff2 1 2020-08-12 03:11:20.4871383 2 Staff2 …
Vanderwood
  • 163
  • 4
  • 13
0
votes
0 answers

DATETIME2 to UNIX timestamp

Is there a simple function to convert the the datetime2 format to output correctly using PHP? I'm able to get a correct date, but the time always returns as 00:00:00, despite showing correctly on the database. I'm using the following to output the…
user1235285
  • 87
  • 2
  • 17
0
votes
1 answer

How to convert nvarchar timestamp to datetime2 in SQL Server?

I've moved my data to a staging table and will eventually insert this data into my main table. I'm having issues converting nvarchar to datetime2. My nvarchar datetime columns have values that look like this: 2019-04-02T12:45:47.000-0400 . I want to…
ccuga
  • 3
  • 1