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
119
votes
3 answers

How to convert LocalDate to SQL Date Java?

How do I convert a LocalDate to a java.sql.Date? Attempt: Record r = new Record(); LocalDate date = new Date(1967, 06, 22); r.setDateOfBirth(new Date(date)); This fails (won't compile) and all I can find is Joda time stuff. I'm using Java 8
Gemtastic
  • 6,253
  • 6
  • 34
  • 53
53
votes
6 answers

.NET DateTime to SqlDateTime Conversion

While converting .NET DateTime (when is default(DateTime)) to SqlDateTime should I always check if the .NET date is between SqlDateTime.MinValue and SqlDateTime.MaxValue [or] Is there a good way to do this.
Sreedhar
  • 29,307
  • 34
  • 118
  • 188
52
votes
5 answers

Converting java date to Sql timestamp

I am trying to insert java.util.Date after converting it to java.sql.Timestamp and I am using the following snippet: java.util.Date utilDate = new java.util.Date(); java.sql.Timestamp sq = new java.sql.Timestamp(utilDate.getTime()); But this is…
Shitu
  • 821
  • 5
  • 12
  • 20
14
votes
4 answers

Check if value is date and convert it

I receive data in a certain format. Dates are numeric(8,0). For example 20120101 = YYYYMMDD There exists rows with values like (0,1,2,3,6) in that date field, thus not a date. I want to check if it is a date and convert it, else it can be null. Now…
Inus C
  • 1,521
  • 1
  • 16
  • 23
9
votes
3 answers

T-SQL Calculate duration in months between different years of ranges

I have a table in SQL Server which contains the duration of a user working for different jobs. I need to calculate the total number of experience for user. Declare @temp table(Id int, FromDate DATETIME, ToDate DATETIME) INSERT INTO @temp ( Id…
Umer Farooqui
  • 208
  • 2
  • 7
8
votes
1 answer

MySQL query by date with big inverval

I have big table with 22 millions records. I want to execute next query: select auto_alerts from alerts_stat where endDate > "2012-12-01" To improve performance I added BTREE index for endData field: CREATE INDEX endDate_index USING BTREE ON…
Taky
  • 5,284
  • 1
  • 20
  • 29
7
votes
2 answers

How to map sql DATE to LocalDate

I want to store a LocalDate in a DATE column and retrieve it unchanged. Both DATE and LocalDate are "local" types by definition. Therefore, the concept of timezone should not interfere in any way. The code below is a minimal example that creates a…
Lars Bohl
  • 1,001
  • 16
  • 20
6
votes
1 answer

Filter data based on date in sql

Im trying to execute the following SQL query and filter out the data based on the date. I need to display a table which filters out the data such that, only those rows which are between the mentioned start_date and end_date Here's the query that I…
shockwave
  • 3,074
  • 9
  • 35
  • 60
6
votes
7 answers

how to convert date into month number?

I have a column Month in my table. The month name and date are stored in this month column like Month 01-JAN-12 02-FEB-12 and so on. How do I convert the DATE into month number such as Month 1 2 etc.
Taoqir
  • 189
  • 3
  • 3
  • 9
5
votes
5 answers

SQL Server - Round TIME values to the next minute

I've found many posts about rounding "down" time values (e.g. https://stackoverflow.com/a/6667041/468823), but I have another problem: I wanna round to the higher minute and not to the lower, how can I do? My code: SELECT PA.ORE AS TOT_HOURS, …
ienax_ridens
  • 255
  • 2
  • 4
  • 12
5
votes
3 answers

How does SqlDateTime do its precision reduction

Consider the following program: DateTime dateTime = new DateTime(634546165144647370); SqlDateTime sqlDateTime = new SqlDateTime(dateTime); Console.WriteLine("dateTime.TimeOfDay = " + dateTime.TimeOfDay); Console.WriteLine("sqlDateTime.TimeOfDay…
Vaccano
  • 78,325
  • 149
  • 468
  • 850
5
votes
3 answers

Entity Framework and SqlDateTime overflow best practices

System.DateTime can take a wider range of values than SQL Server's DateTime. Hence there is class System.Data.SqlTypes.SqlDateTime which mimics the later. Consequently I would have expected Entity Framework to choose SqlDateTime, but it didn't. So…
Buh Buh
  • 7,443
  • 1
  • 34
  • 61
5
votes
1 answer

How to extract a Date from an SQLDateTime object in Mathematica

I am trying to do a plot of a time series with DateListPlot. I want to feed it a time series I obtain from an SQL database. When I retrieve the time series the list is composed of SQLDateTime entries that DateListPlot doesn't understand. In[24]:=…
andrewz
  • 4,729
  • 5
  • 49
  • 67
3
votes
2 answers

Select Range of SQLDateTimes

table = {{ID1, SQLDateTime[{1978, 1, 10, 0, 0, 0.`}]}, {ID2, SQLDateTime[{1999, 1, 10, 0, 0, 0.`}]}, {ID3, SQLDateTime[{2010, 9, 10, 0, 0, 0.`}]}, {ID4, SQLDateTime[{2011, 1, 10, 0, 0, 0.`}]}} I'd like to return all cases in table in which the…
Rose
  • 129
  • 6
3
votes
4 answers

Get the max possible time of a date SQL Server

What I am trying to do is take a date in SQL Server and find the last possible hour, minute, second, and millisecond of that date. So if the date is this: 2021-02-16 13:08:58.620 I would like to return: 2021-02-16 23:59:59.999 I have tried something…
Eric
  • 212
  • 2
  • 15
1
2 3
11 12