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
0
votes
1 answer

Postgres: global setting to always return TIMESTAMPTZ in exactly the same format? i.e.: 6 digits of sub-seconds + 4 digits of timezone offset

Postgres will return TIMESTAMPTZ values using inconsistent formats, depending on how many zeros are after the . See these examples: 2020-10-24 13:21:05+10 2020-10-24 13:21:05.1+10 2020-10-24 13:21:05.12+10 2020-10-24 13:21:05.123+10 2020-10-24…
LaVache
  • 2,372
  • 3
  • 24
  • 38
0
votes
1 answer

Problem with finding datetime entries which are related to today in a SQL Server table

I have a table with a varchar column with different values in it. Some of the values in this column are in fact datetime stamp but written in varchar data type. I wish to find entries which contain datetime AND are related to today. So, my table is…
Iraj
  • 319
  • 3
  • 17
0
votes
1 answer

Showing a row for every minute based on start and end time

I have a table that looks like below: task_id start_date end_date t1 2020-05-01 8:00:00 2020-05-01 9:45:00 t2 2020-05-01 8:30:00 2020-05-01 9:00:00 t3 2020-05-01 8:45:00 2020-05-01…
0
votes
1 answer

SQL Server - Convert datetime to JSON date format

How can I convert SQL smalldatetime or datetime like this: select cast(getdate() as smalldatetime) To JSON format like this: /Date(1576278000000+0100)/
hoggar
  • 3,699
  • 5
  • 31
  • 41
0
votes
2 answers

Select query to return only the min datetime without group by?

My table displays as below, |_______________|____________|_____________________|______________________| | ENTRY POINT | NAME | DATE OF ENTRY | DATETIME OF ENTRY |…
0
votes
1 answer

Will a SQL view filtered by large datetime always provide current data?

If I create a view today for a table that continuously keeps getting data, using date filtering from 1900 and 2100, for example, will that "copy" become truncated to the moment that I build the view or since it is being filtered to a very large date…
Eunito
  • 416
  • 5
  • 22
0
votes
3 answers

Get Day, Month, Year, Lifetime total records with one query w/ optimizations

I have a Postgres DB running 7.4 (Yeah we're in the midst of upgrading) I have four separate queries to get the Daily, Monthly, Yearly and Lifetime record counts SELECT COUNT(field) FROM database WHERE date_field BETWEEN DATE_TRUNC('DAY'…
Phill Pafford
  • 83,471
  • 91
  • 263
  • 383
0
votes
2 answers

Select a date in a string and convert it to datetime

I have a string like: 'SPY US 03/20/20 P45' I want to select just the date from the string. My current query is: Select Ticker, SUBSTRING(Ticker, PATINDEX('%[0-9][0-9]/[0-9][0-9]/[0-9][0-9]%',o.Ticker),8) AS 'myDate' FROM TABLE This returns: 'SPY…
0
votes
1 answer

NHibernate : SqlDateTime Overflow When Deleting Entity

I'm trying to delete an object and I receive a SqlTypeException : SqlDateTime Overflow. So, today I activated the "Show SQL" property in the configuration, and to my surprise I discovered that when I try delete this entity NHibernate actually…
jhenriquez
  • 181
  • 9
0
votes
2 answers

Getting SqlDateTime overflow. exception in 2008

am passing default dates (startdate & enddate) to an sp as ('1/1/1753 12:00:00 AM' & '12/31/9999 12:00:00 AM'). This was working fine in 2005, but am getting "SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM"…
shoab
  • 545
  • 3
  • 7
  • 19
0
votes
2 answers

SQL BETWEEN Time doesn't show results

Could use fresh POV help :) Need to show trips between midnight and 4AM. StartTime column is of type DATETIME. I already tried CAST(StartTime AS TIME) BETWEEN CAST('00:00:00' AS TIME) AND.... but it didn't show the correct results and so I've…
TommyD
  • 15
  • 4
0
votes
1 answer

Group result into hourly subgroups

I have a query which results in total booked time on a resource in a given period of time/days. I want to split the total amount booked to be grouped by the hour. SELECT resourceID, SEC_TO_TIME( SUM( CASE WHEN…
Jeppe
  • 13
  • 3
0
votes
1 answer

DATEDIFF causing The conversion of a date data type to a datetime data type resulted in an out-of-range value

Why would the following SQL cause the error? SqlException: The conversion of a date data type to a datetime data type resulted in an out-of-range value. I believe it has to do with the DATEDIFF and the type of DATE for StartDate? (CASE WHEN…
Mike Flynn
  • 22,342
  • 54
  • 182
  • 341
0
votes
1 answer

Search between German dates when they are strings

I have a MVC project with two fields where the user can input two dates. Model: [DisplayName("Date From")] public string DateFrom { get; set; } [DisplayName("Date To")] public string DateTo { get; set; } The two dates are belonging to one column…
0
votes
1 answer

Convert Excel column date with different patterns - Oracle PLSQL

I'm trying to convert the column DATA_EMISSAO which has a char format but contains all dates for the Table (it only contains dates). The problem is: the way information was loaded into Oracle let the row set with different patterns as shown…
Petter_M
  • 435
  • 3
  • 10
  • 20