Questions tagged [sqldatetime]

The SQLDateTime tag is for questions related to how database SQL queries handle date and time information.

Databases can store date and time information in various ways. The is used for questions related to defining and accessing date/time data. Some considerations for this type of data are

  • Precision
  • Calculations
  • Business rules
  • Scheduling

Most database software allows date types that include both the date and time of day. There are various types of date types that can include timezone information, and interval information.

See the for questions relating to functions used for determining things such as last_day(date) which returns the last day of the month for the specified date, and functions for returning the current date or timestamp.

177 questions
3
votes
3 answers

How to add hours, minutes and seconds to a datetime column in SQL?

I have the following datetime column in my table "UpdatedTime" Sample value: 2021-12-31 00:00:00.000 I need to manipulate the hours, minutes and seconds to become 23:59:59 (i.e. a second before midnight.) Expected Value: 2021-12-21…
Wymo Oo
  • 45
  • 1
  • 1
  • 5
3
votes
2 answers

Which timezone is java.sql.Date toLocalDate using

I'm surprised that java.sql.Date has a method toLocalDate(). java.util.Date or java.time.Instant don't have comparable methods. It seems that in java.time, a ZoneId must always be provided to obtain "LocalFoo" or "OffsetBar". From the javadoc of…
Lars Bohl
  • 1,001
  • 16
  • 20
3
votes
4 answers

SQl Difference in date

I need find difference in two date in years but years should be in decimal example i need to find difference between 16-jun-2010 to 30-Sep-2014 and it should be 4.30 yrs i try following way select DATEDIFF(YY,'16-jun-2010','30-sep-2014') as…
user5746445
3
votes
4 answers

C# string to SqlDateTime: how to set format for recognition?

I need to use SqlDateTime.Parse(val) where val is a string such as " 23.3.1992 00:00:00 ". The string is in European format, that is, day precedes month. However Parse wants "American" format. How I can tell it to use particular datetime format /…
onkami
  • 8,791
  • 17
  • 90
  • 176
2
votes
2 answers

Join on closest date in SQL

Hi I have two tables which I have to join on ID field and then on closest date ( only if the date is within one hour range more or less), the reason is both tables are not updated at same time so time is little off between the two ( but max delay is…
2
votes
1 answer

Formatting date to 2017-06-21T12:33:47.879 format

In DB I have TIMESTAMP datatype like 17/06/21 12:33:47,879000000 and I would like to select in format 2017-06-21T12:33:47.879 Edit: I tried to_char(MODIFIED_TIME,'YYYY-MM-DD HH:MI:SS:FF') but getting 2010-11-12 11:47:50:294000. How can I add this…
pqa1222
  • 75
  • 1
  • 8
2
votes
1 answer

Why can i insert MaxDate but not MinDate

when inserting into my table with a nullable datetime column, inserting DateTime.MinDate raises the error: "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value." Yet when i do MaxDate it works…
Grace
  • 2,548
  • 5
  • 26
  • 23
2
votes
1 answer

How to get start date and end date between two dates in sql server

Hi everyone i am working on some kind of accounting system and encountered some difficulties. the question is already been answered by Abdul Rasheed in this site. This is the code declare @sDate datetime, @eDate datetime select @sDate =…
Red
  • 29
  • 9
2
votes
3 answers

Convert varchar time (for time > 24 hours) to float

I have a column with time records that represent the difference between two dates. Some of these records exceed 24 hours. As time syntax doesn't account for time records > 24 hours, I've had to convert these records to varchar hh:mm:ss as outlined…
2
votes
3 answers

Display sum from previous year

I have select statement like below: select [Fiscal Year], sum([value]), YEAR(DATEADD(year,-1,[Fiscal Year])) as previous_year from [table1] group by [Fiscal Year] How to add after column previous_year, sum([value]) from previous…
4est
  • 3,010
  • 6
  • 41
  • 63
2
votes
2 answers

SQL remove colliding part of datetimes in a table according to value of a column

I have a table like MemberID MembershipStartDate MembershipEndDate type ============================================================================= 123 2010-01-01 10:00:00.000 2012-12-31 23:00:00.000 1 123 …
2
votes
1 answer

SQLBulkCopy can't convert Time to DateTime

I am writing a small utility to copy a database from a proprietary ODBC database into a SQL Server database. Everything is working great, except when I use SQLBulkCopy to copy over the data. It works in most cases, but not when it's trying to copy…
John Virgolino
  • 1,828
  • 3
  • 16
  • 25
2
votes
2 answers

why c# disallows to assign SqlDatetime.MinValue to datetime but allows comparison

The following code compiles fine with comparison operator. If(dateTimeVariable > SqlDateTime.MinValue) //compiles Ok. dateTimeVariable is of type DateTime { } However, the following code fails to compile. DateTime…
ANewGuyInTown
  • 5,957
  • 5
  • 33
  • 45
2
votes
4 answers

Finding max(date) from the resultant query output

I have below 2 tables: table1 objName | rptName | srcTblName | srcFileName | srcDateColName -------------------------------------------------------------- obj1 | rpt1 | srcTbl1 | srcFile1.csv| srcDate table2 FileName |…
Touhid K.
  • 351
  • 1
  • 5
  • 23
2
votes
2 answers

String date to SQL date adding years

I am using SimpleDateFormat to convert a date string to java.sql.date. On converting, I am getting a issue, i.e. Year is getting added automatically. Code: String d="2012-12-04T08:48:00"; SimpleDateFormat formatter = new…
Abhishek
  • 1,999
  • 5
  • 26
  • 52
1
2
3
11 12