Questions tagged [datetime]

for questions specific to data types that contain both date and time parts.

Filter by
Sorted by
Tagged with
-1
votes
1answer
19 views

How to extract variation values with MYSQL query

This is our situation: We have a +50MM records. The DB structure is as follows: id Field: int(15) auto_increment, DATETIME field, METER field: varchar(15), RECORD_A field: float(10,2) Each METER ...
0
votes
0answers
18 views

Postgres cast MI:SS formatted string to “interval minute to second” type

I have a data source with the time information being formatted like this: 'MI:SS'. I am trying to coerce that to a native postgres INTERVAL or TIME type so I can leverage the equivalent operators. I ...
0
votes
1answer
13 views

Using a string time field to build a timestamp with date produces out of range

I am working with some times that display a 24+ hours to signify that the schedule goes into the next day and I am trying to convert them into proper time stamps by detecting if the hour is >= 24 ...
1
vote
1answer
15 views

Convert specific time format to common one

Environment: I have 'duration' datas stored as varchar(4) in a table. 2 first characters are hours, 2 last characters are minutes. E.g.: 0100 means 01:00 0456 means 04:56 and so on... What I need: ...
5
votes
1answer
110 views

SQL Server 2012 equivalent of AT TIME ZONE capability

Is there a way in SQL Server 2012 to get what the server time zone would be on a particular date/time? In SQL Server 2016, you have AT TIME ZONE, but that's not available in 2012. I have a ...
0
votes
1answer
312 views

How to pass, specific day month and year in the below query?

I have registration according to the data in a table and I want to show the whole month, I found the easy solution with below query but I do not know how can I pass specific day, month and year in ...
1
vote
4answers
5k views

MySQL - query to get length of service in Years, months, days

I have the following query that I'm trying to get the length of service of a person at their company. The idea is to find how many years, months, and days they have served there. For example: ...
0
votes
2answers
166 views

Finding Count of Occurrences & Time Gap between a Timeline in MySQL

I have a Table, like the below, which has a timeline and values (like YES/NO) that are coming from different sensors. How do I do the following: How many times there has a been a flip-flops (for YES ...
3
votes
0answers
19k views

MySQL - Truncated incorrect datetime value on update statement

I have an application which produces log files. These log files include a Timestamp field in the format 2015-08-25T09:35:01 UTC. (there will be approximately 60 logs produced at 0.25 GB per day). I ...
0
votes
1answer
502 views

Select different dates from mysql

I have a database structure like this ID | title | startTime | endTime And what I need is to get 3 records from the database where the first recorder is following this structure DAY(NOW())-1 the ...
1
vote
1answer
866 views

Weed out certain rows where timestamp is within interval

Given a table structure: create table contacts ( contact_id int(8) not null auto increment, #primary key pid int(8) not null, #personal id contakt_time datetime, ...
0
votes
1answer
40 views

Stored procedure to change string to datetime in MySQL

This is a follow up to this question. Turns out the driver that I am using (can't change it) is not compatible with timestamp values. Lets say it is set in stone that I have to load the data into my ...
0
votes
2answers
39 views

Does a NULL DATE use as much storage as a value?

I need to store a DATETIME value that may or may not have a date. My options are: | starts DATETIME | |---------------------| | 0000-00-00 12:38:06 | | starts_date DATE | starts_time TIME | |----...
1
vote
1answer
47 views

Office Hours in PostgreSQL

How to store office hours in PostgreSQL rows, so that I can calculate the office hours. Example: We have open from 9:00 to 18:00 from Monday till Friday. Saturday we have open from 10:00 to 15:00 ...
16
votes
3answers
146k views

SQL Server Isnull Returning 1900-01-01 when field is null

The following piece of code is returning 1900-01-01 when the DOB field is null. I wanted (and expected) it to return an empty string ('') but it's not. How should I proceed to get my desired results? ...
0
votes
1answer
42 views

What exactly is the datatype input into a DATETIME value in MySQL

I am trying to get data from a PLC directly into a MySQL 8.0 database (using MySQL Workbench). I need to know what data type the input value is for a column set to DATETIME so I can send in the right ...
1
vote
1answer
246 views

Parsing DATE while copying csv file into PostgreSQL table

I have a long series of .csv files, which I want to import into a local database. I believe my query is correct, but there are some problems in parsing DATE and TIMESTAMP columns. PostgreSQL reads ...
4
votes
2answers
2k views

Split up interval into year slices

Being a novice Postgres user, I have a table ad in my PostgreSQL 9.5 (x64) database with 87 rows. In addition to other columns, it has two columns 'start' and 'end' having date-time duration range ...
0
votes
1answer
2k views

Phpmyadmin feed a timestamp column with “0000-00-00 00:00:00”?

in PhpMyAdmin (OVH Mutu), a table with column type timestamp. Impossible to put into this colum a timestamp : Always display datetime like 2017-01-09 23:02:01 !!! It generate several problmes : ...
0
votes
1answer
990 views

Pass 'interval' value to date_trunc function in PostgreSQL procedure

I am fetching the "age" of two timestamp columns (End and Start) and further choosing it as to_char 'MM' format. So I have the difference of the months from two timestamp columns. The syntax in the ...
0
votes
1answer
364 views

How can I get the last second of the last month as a default parameter value?

I am trying to get the last second of the last month as a default value for a parameter. I can get the last day of the last month from this query on social.msdn.microsoft.com last month last day ...
0
votes
1answer
50 views

Converting DATE and TIME integers to timestamp

I am trying to get a timestamp by combining date and time columns in my PostgresQL database and am running into errors. Here is what I have: +-----------+-----------+ | StartDate | StartTime | +-------...
0
votes
2answers
157 views

How to interpret timestamps stored as 10-digit negative integers?

I've inherited an undocumented MS Access database where the date/time values are stored in an INT column and the majority of values I've seen so far are 10-digit negative integers. How do you ...
10
votes
4answers
2k views

In the same query INSERT, can two VALUES being NOW() return a different time?

I met a query similar to INSERT INTO mytable (id, Created, Updated) VALUES (null, NOW(), NOW()) having column definitions | Created | datetime | | Updated | datetime | Will in this case MySQL ...
2
votes
1answer
556 views

Calculate Total Working Minutes in MySql

I have a design a table for attendance and here are the genral fileds AttendanceMachineLoginId EmpId AttendanceDateTime Whenever user will come to office, he has to make his attendance. The first ...
1
vote
2answers
198 views

“1292 Incorrect datetime value” when updating an “empty” datetime field

I have an updated_at field that was not initially set with default datetime value on the server. For a short period, a bunch of records got inserted with an "empty" value and are showing up ...
0
votes
3answers
48 views

How to re-write this query or restructure my table for SPEED

I have an InnoDB MySQL table of this structure: column type service varchar(16) url varchar(255) datetime datetime It contains logs for requests made to one of multiple services. It contains ~3 ...
6
votes
2answers
16k views

How to get minimum and maximum for grouped timestamps

I would love to know how to create a view that groups timestamps in 10 minute nearest 10 minute intervals and contains each minimum and maximum timestamp for each. So a table that looks like this: | ...
0
votes
0answers
61 views

Compare datetimes with dfferent timezones in MySQL

I have a field `opened_at` in MySQL table that stores datetimes in string format with different timezones: 2021-01-30T18:07:40+02:00 2021-01-31T01:32:40+05:00 2021-01-31T21:17:40+03:00 etc. I need to ...
1
vote
1answer
32 views

Mealplan: Allow ordering until 9am

Imagine you have a meal service and everyday there is a different meal which customers can order. Mon, Dec 12: Pasta Tue, Dec 13: Pizza Wed, Dec 14: Gnocci Orders are possible until 9am. This mean ...
0
votes
1answer
85 views

Calculations involving thresholds between two tables

I have a table comment and a table price like below. The key columns in both tables are ticker_id, price_datetime and price_open. The last column threshold in table comment (which currently NULL) is ...
0
votes
2answers
172 views

How to query time series with gaps between a given date range in PostgreSQL?

My problem is I don't know how to query time series data between a specified date range where the data has gaps in it and the last known value which should carry forward for each date falls outside ...
8
votes
2answers
303 views

Inability to query underlying table of a schema-bound view

I migrated a database from SQL Server 2008R2 to SQL Server 2019 (both Enterprise Edition) using the backup-restore technique, and a set of post-transfer actions like DBCC UPDATEUSAGE or UPDATE ...
16
votes
5answers
78k views

How to create a row for every day in a date range using a stored procedure?

I would like to create a stored procedure that will create a row in a table for every day in a given date range. The Stored Procedure accepts two inputs - A start date and end date of the date range ...
2
votes
1answer
78 views

Date time cast preferred method

What would be the preferred method for speed and less database stress using a between or less than? SELECT LogId FROM [Master].[dbo].log mlog WHERE cast(LogDate as Date) BETWEEN '2019-01-01' AND '2019-...
-2
votes
1answer
69 views

Convert Varchar to Datetime

I have a database field Column_A which is in Varchar(16) not null and the values are for example 20191210215033CS but I want to break it like 2019-12-10 21:50:33 Since it is a production database ...
4
votes
1answer
364 views

SQL Server with French_CI_AS Collation date conversion

I have a French installation of SQL Server using French_CI_AS Collation. For legacy reasons, a table column stores data as VARCHAR which is later converted to the right type, akin to variant in C++. ...
1
vote
1answer
147 views

How to query from the result of a changed column of a table in postgresql

I am working with Presto on Amazon Athena. I have a string time column in a table and now I want to change that time to date time type and then query data for selected dates. Is there a direct way to ...
3
votes
2answers
15k views

Postgresql update timestamp without timezone to have timezone

When I created the table, a Timestamp column without timezone was created. All the imported time is in UTC. Now I want to add the timezone information explicitly, and I have altered the column ALTER ...
0
votes
1answer
42 views

DateTime conversion fails when the datetime has seconds [closed]

This seems to be most discussed, but I could not arrive at a solution yet. I have a date format and have to add a month to it (DATEADD should not be used as my date is string initially) and finally ...
4
votes
1answer
267 views

DATEADD and DATEPART with milliseconds yields strange results

I have a table containing the date in unix time and a separate milliseconds field. I now try to create a date from the two fields for later calculation (e.g. filtering on a time range). After adding ...
2
votes
1answer
84 views

Indexing a date column in MySQL doesn't work if a date function is used

I have a table with the following schema table_name id int task_id int completed_date datetime (INDEX IX_TBL_NAME_COMPLETED_DATE) I run EXPLAIN on this query EXPLAIN SELECT * FROM ...
0
votes
1answer
28 views

Strange max(date) return in reader vs writer aurora mysql [closed]

Something very strange happening here which I can't point out. Using AWS Aurora, select max(date) in the writer gives me one date, in the reader it returns strange date and warnings.. Column is ...
1
vote
1answer
56 views

Subtract column value from date in days or months

I want to subtract the value in column lag_days from current_date. Usually I would do current_date - interval '1 day' I'm getting syntax error on the following example to subtract by days: dkarchive=&...
0
votes
2answers
52 views

Can somebody please tell what is the difference between these two date comparisons?

So I have 2 queries as follows: f.DATE >= (GETDATE() - 3) f.DATE >= CAST(CONVERT(VARCHAR(10),GETDATE() - 3,101) AS DATETIME) I think they are the same but the second one gives me more rows ...
6
votes
5answers
7k views

How do I find the next saturday in MySQL

I have trigger and a stored procedure in it (so SP runs when trigger runs). I need a function which finds the next saturday to put in SP. So lets say, it is Wednesday (2015-7-22) today. If my ...
0
votes
1answer
4k views

Select where datetime is greater than other datetime which may not exist

I have a table with a field eventtime of type datetime and a different table with a datetime field. I need the minimum eventtime that is greater than the greatest datetime field from the other table ...
7
votes
4answers
73k views

get all dates in the current month

i have a query in MySQL which serves me very well by getting all the records within the current month; SELECT date_field,val FROM MY_TABLE WHERE date_field>=(CURDATE()-INTERVAL 1 MONTH); The ...
0
votes
1answer
23 views

How to insert '1001-01-01 00:00:00' into MariaDB when altering a table?

I created a table in HeidiSQL: CREATE TABLE `publish_dt` ( `ID` BIGINT(20) NOT NULL AUTO_INCREMENT, `TS` DATETIME NULL DEFAULT NULL, `Text` VARCHAR(50) NOT NULL COLLATE 'utf8mb4_unicode_ci'...
5
votes
2answers
232 views

Datetime progressive sum PostgreSQL

my first question here, but I looked in many other places and could not find the answer to my problem. id | track_seg_id | time ----+--------------+--------------------- 1 | ...

1
2 3 4 5
7