Creating Datetime Data Object From Date And Time Objects
I have date and time objects that correspond to eachother. I want to add a certain amount of minutes and hours to them and get the resulting date and time.
I was planning on creating a datetime datatype from the two and then using the date_add() function and then convert back; however, I do not know how to create a datetime object from two seperate date and time types and then back to seperate types, or whether it is even possible.
View Complete Forum Thread with Replies
Related Forum Messages:
How To Pass A Java.util.Date Object To A DATETIME Column Definition?
I am writing to a MySQL table via JDBC. I have some column definitions with type DATETIME. Here is my table definition: mysql> describe sessions; +-----------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------+-------------+------+-----+---------+-------+ | uid | int(11) | | PRI | 0 | | | site_id | varchar(32) | | | | | | session_id | int(11) | | | 0 | | | context | varchar(32) | YES | | NULL | | | create_time | datetime | YES | | NULL | | | expiration_time | datetime | YES | | NULL | | +-----------------+-------------+------+-----+---------+-------+ 6 rows in set (0.00 sec) My statement text is: Code:
View Replies !
Creating Date And Time Fields
What's the correct way of creating date and time fields. Do I set a default for these fields of NULL so I may query NULL values instead of '0000-00-00' values? What's the preferred way?
View Replies !
Date Format :: DATETIME From LOAD DATA With Lot Of Zeros
I have to insert data into a mysql database from a txt document. This document contains several dates in this format: 08-01-2009 09:24:32. I tried to use the field format DATETIME in the mysql database, but this expects dates formatted as 2009-01-08 09:24:32, so the LOAD DATA statement comes up with a lot of zeros. I can't change the date in the txt document (and I have to upload this sort of documents regularly) so I wonder if anyone can tell me how I can insert the dates from my txt documents into mysql properly (I now use the field format VARCHAR with 19 positions, but I don't think I can make mysql to treat this kind of information as a date).
View Replies !
Converting Time Date Values To An Absolute Number For Data Retrieval
We have a medical DB which stores several medical variables from real cases. We use this data to build display trending information on a visualization display for doctors. Pulling and rendering graphically ALL the data takes time and processor that may not be available in a real world situation. What we want to do is to pull data at specific intervals of time based on the time length a doc wants to view. For example: if we have 2500 records all of which have a time stamp and each record is for an interval of 15 seconds how can I query the DB such that I can pull every data point at an interval of 75 seconds apart from the beginning time and display it? I was thinking if I could convert the timestamps to an absolute numeric value (assuming MySQL starts it's times at some point in the past) then I could figure out the query from there.
View Replies !
Storing A Large Data Struct/object In MYSQL
I have the following structure. typedef __nogc struct RemoteDisplayInfoType{ int HistData [512][512]; int channelNdx; double xVar[2]; double yVar[2]; double paAngle[2]; }RemoteDisplayInfoType; I want to store this in MySQl database and retreive it back. I am using ADO.Net with managed c++.
View Replies !
DateTime Without Time
I have a difficult case and need your advice: For managing events in my online application I need to be able to input the start and end. They can be inserted either as a date only or as a date and time both. And I save this data into the DATETIME format. The problem is, if only a date is inserted, MYSQL will put the missing time information automatically as '00:00:00' but I don't want this. Because it will display the time as '00:00:00' which is wrong. Is there no way to save into DATETIME format without the time?
View Replies !
Comparing Datetime And Time
I need to compare two values : the first one is in DATETIME format and the second one in TIME format. If I compare the two values with an usual operator, will MySQL extract the "time" part of the DATETIME and compare it to the TIME value? If not, what function can I use to extract the "time" value? I have noticed the existence of TIME(expr) function, that extracts the TIME value from 'expr'... but it works only if 'expr' is a string, not a DATETIME.
View Replies !
PHP/MySQL Sorting By Date & Time (using Non Military Time)
This is probably a simple issue but I have searched online and can't find an answer. I am using PHP/MySQL and I guess the most intuitive would be to have three select boxes containing HOUR / MINUTE / AM,PM option. Then store the time into mysql using there functions so I can output the data sorting them all by date and time. All the examples I have seen are for military time only but I'm sure there has got to be a simple mysql function or php function that converts non military to military and a formatting function to display with the AM / PM. But I have not found it.
View Replies !
Elapsed Time Between 2 DateTime Values
MySQL Version 4.0.20 on a Linux server. How does one get the elapsed time between (2) DateTime values? I need the answer to the nearest minute. Is upgrading to Ver 5 with its more robust date/time functions the only solution? You can directly subtract 2 DateTime values and a long integer results. What is that number?
View Replies !
Datetime Field Updateing Time Only
How would I update the time only on a datetime field? The filed is: "2008-09-14 12:06:00" and I want to change it to "2008-09-14 12:16:00". If I use  update field_name set field_name = TIMEDIFF('2008-09-14 12:06:00', '2008-09-14 12:16:00');Â
View Replies !
Update Time Ony In Datetime Field
How do I update the time portion in a datetime type field? There are several rows containing various times and I want to make them all the same: 11:30:00. I have tried doing the following w/o success: update field set field = "date(field) 02:02:00"
View Replies !
Update Just Time In Datetime Column
I have a datetime column called foo, it currently has dates in it with all times set to "00:00:00". I would like sql to update all the rows and set the time to "15:15:00" but leave the dates as they are today.
View Replies !
Datetime :: 12 And 24 Hours Time Format
I am using webservice to download data from mySQL to SQL Server. I noticed in sql server datetime format makes the hour 12 to 00. for example 2008-06-12 00:40:47.000 This is really 2008-06-12 12:40:47.000 My question is how does mySQL treats 24 hours format. with 12 or 0 for the hour "12".
View Replies !
Datetime :: Start Date And End Date
I have a to generate an hourly report. I have a web page in which a user selects a customer, a product and time frame(startdate and enddate). the start date selected will be in these format 05/19/2005 and the end date will be these format. In the database i have a datetime column in these format. 2005-05-19 13:27:17.441043-04 so the question is how do i write a select query. and when i run mysql select query i should get all the record which fall under the given time frame. now i want to get a hourly record. means at which hours that records was created.
View Replies !
Function To Convert From DateTime To Relative Time
I have a DATETIME column and I looking to write a function which does the following: Takes in the DATETIME and compares it against the current time, and returns a string in any of the forms below, depending on the value of the DATETIME: 'You updated your settings 4 seconds ago.' 'You updated your settings 2 minutes ago.' 'You updated your settings 6 hours ago.' 'You updated your settings 12 days ago.' But its smart and automatically scales from seconds, to minutes, to hours, to days, rounding either up or down.
View Replies !
DATETIME -> DATE
I have a table with a DATETIME column named 'date'. I find that my queries often do 'DATE(`date`)' and so I figure that it'd make more sense to have a column with the actual date in it, rather than the DATETIME. I could then make that column an index which would speed up my queries.Does that make sense?If so, how best to do this. Something like this? ALTER TABLE rawdata ADD daydate DATE after date, ADD INDEX (daydate); UPDATE rawdata SET daydate=DATE(date); It seems wasteful/etc to duplicate the actual date, but I can't remove the DATETIME column since it's already used in other applications. Is there some way to have a column whose value is automatically derived from another column?
View Replies !
Creating A TIME Table?
Here is an example of a time I'm working on: +-----------+---------------+ | record_id | last_modified | +-----------+---------------+ | 3 | 14:46:32 | | 10 | 16:48:26 | | 11 | 17:21:03 | | 12 | 11:56:23 | +-----------+---------------+ etc... It's simple. Shows a record and the time of day it was last modified at. What I'm wondering, is it more efficient to create a separate 'time' table, listing every second of the day (00:00:00 thru 23:59:59) and linking to this table in the last_modified column. +-----------+-----------------------+ | record_id | last_modified_time_id | +-----------+-----------------------+ | 3 | 35304 | | 10 | 37030 | | 11 | 41003 | | 12 | 25030 | +-----------+-----------------------+ (those numbers are just examples and are not the real numbers) +---------+----------+ | time_id | time | +---------+----------+ | 1 | 00:00:00 | | 2 | 00:00:01 | | 3 | 00:00:02 | | 4 | 00:00:03 | +---------+----------+ etc... So basically you can see that one table simply holds all the time values for the day. The other table, instead of actually having a time value in its field, actually links to the time_id in the other table. Is this efficient? Or a waste of time? Could I take it a step further and actually split up the time table into 3 other tables? Hours, Minutes, Seconds? Save even more space?
View Replies !
Convert Int Date To Datetime
I have a table that unfortunatley has a field 'DateSold' with datatype of int that SHOULD be datetime. So, I am trying to do a cast/convert. The int is stored as 20040520 (which means 5/20/2004) I tried saying Select col1 from table where cast(DateSold as DATETIME)[color=blue] > '1/1/2004'[/color] but of course it bombs out. What is the most efficient way to do this? Is there a way to cast it without doing some crazy string manipulation?
View Replies !
UPDATE Date Of DATETIME
I have a datetime column. And for some random row of data, I want to change the date (but not the time) of the datetime column. How do I do this? before: datetime = 2006/04/03 12:30:25 if I do: UPDATE table SET DATE(datetime)='20060404' where id=whatever; I get this: datetime = 2006/04/04 00:00:00 I also tried: UPDATE table SET DATE(datetime)='20060404'+TIME(datetime) where id=whatever; but that seems to take the time and add it to the date instead of concatenate it or something. Anyways, my point is, I'm trying to update the date and only the date for a datetime value without adjusting the time. I know there is some simple way to do this but I'm far from a MYSQL syntax expert.
View Replies !
Date & Datetime Question
I'm trying to check for dates that are >= but with a Date field, it doesn't work with NOW()... exp_date >= NOW() How can i have mysql ignore the hours/min/sec and just compare date to date properly?
View Replies !
Date-time Overlaps Another Time
had a time question in mysql... i have a start and end time for a meeting table and i am comparing whether a new meeting conflicts with another meeting in same room on the same date. i was wondering if i could check whether the 'date-time duration' in anyway overlaps another meetings date-time duration. visualized below... ............|____compareToThisMeeting__| .....|_________meetingNewOverlaps__________| i was doing something dumb before i realized i needed soemthing more complex (checking whether the start time of new meeting was 'BETWEEN' the start and end times of a meeting and whether the end time time is as well but i forgot the duration/middle value hehe). (using asp) and just returning booleans with a mySQL SELECT statement is what i am looking for like... //within a loop in asp for meetings on same date/room "SELECT '"+ year+"-"+month +"-"+day +" " + startHourString +":" + startMinuteString +":00''"+ " BETWEEN '"+ thisMeetingStart +"' AND '"+ thisMeetingEnd +"'"; (this doesnt cover the 'middle' overlap areas though)
View Replies !
Comparing DATETIME Field With Date...
I'd like to make query which compares two dates - one from database, ang second in php (date("Y-m-d H:i:s")). I'd like to make query which gives me back those rows where the date from db is more than three days older than current date.
View Replies !
DateTime Sorting - Put Empty Date To The End
is there a way to sort DateTime and put the empty DateTime (0000-00-00 00:00:00) to the end? Example: SELECT dat FROM blah ORDER by dat It shows me: 0000-00-00 00:00:00 2009-04-07 13:10:00 2009-04-08 13:10:00 but I want: 2009-04-07 13:10:00 2009-04-08 13:10:00 0000-00-00 00:00:00
View Replies !
Date Field, Time Field, Sort By Date And Time
I have a MySQL date field (e.g 13/12/2006) and a MySQL time field (e.g.13:00) in the same row. I'd like to join these two fields to make a date/time field (e.g. 13:00 13/12/2006) on the fly and to be able to sort the query results on the resulting field.
View Replies !
Date Extraction Issue From Datetime Column
I would also like to only provide a date in the where clause and not a timestamp (the field is of type datetime). I have tried using the date function but it does not appear to work. I tested the date function as per mysql: manual(http://dev.mysql.com/doc/mysql/en/d...-functions.html) but I get the following error: SQL-query: SELECT DATE( '2003-12-31 01:02:03' ) MySQL said: #1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '('2003-12-31 01:02:03')' at line 1
View Replies !
Get Back The Date Part Of A Datetime With A Select
My web site uses the same request, on one hand, to make selections at precise hours, on the other hand, to make selections for day: SELECT thing FROM `table ` WHERE dates = ' 2008-01-01 09:06:40 ' The daily table `table ` contains a column date in the format "date" (YYYY-MM-DD). With my former version of Mysql (5.1.14-beta), all the lines containing date = '2008-01-01' were selected. My problem is that since I've changed my Mysql version these are lines like date = ' 2008-01-01 09:06:40 ' which seem to be selected : so nobody in my daily table... Is it a problem of version of Mysql? Nevertheless my newone version is more recent (5.0.51a-6) than the former.Is it possible to select lines having '2008-01-01' without modifying my SELECT?
View Replies !
Generating DAILY Min&Max Over A Period Of Time, Based On A "DateTime" Field
how to print the minimum and maximum of a specific field, between two datetimes (both having the time 02:00:00) - so I did this: WHERE ((tblvalues.dtLPDateTime)>="2006-01-01 02:00:00" And (tblvalues.dtLPDateTime)<"2006-01-03 02:00:00")) Now I want to print those min and max values but for each day in this cycle, i mean, for this example, there would be two records like: Day Min Max 2006-01-01 02:00:00 -> 2006-01-02 02:00:00 | 40 | 59 2006-01-02 02:00:00 -> 2006-01-03 02:00:00 | 49 | 68 where at this point i`m getting min=40 and max=68
View Replies !
Calculate Datetime Data
I am using MySQL 4.0. I have a table: foo with Id, TimeStamp columns. TimeStamp is in DATETIME format. I want to retrieve all Ids with (Now - TimeStamp) > 30 days. How can I do that.
View Replies !
Datetime And Timestamp Data Types
I am new to mysql. Can someone tell me what is the difference between "Datetime" and "Timestamp" data types? also, can we have information correct upto a fraction of a second in any data type of MySql? if yes, in which data type? and upto what depth? (mili second, micro second. .... and so on).
View Replies !
Data Truncation: Incorrect Datetime Value
My Java statement is as follows: user.setLastLogin(new java.sql.Date(0)); The type for LastLogin in the database table is TIMESTAMP. From what I understand, java.sql.Date gets you the date will milliseconds as in <date> HH:MM:SS.SSS which is what I understand SQL requires. But, I get the error "Data truncation: Incorrect datetime value: '1969-12-31 16:00:00' for column 'LAST_LOGIN' at row 1"
View Replies !
How To Store Am/pm In A Datetime Data Type
I have the following: $now = date("Y-m-d h:i:s a"); INSERT INTO table_name (start_time) values ('$now'); Column Name -- start_time Data Type -- datetime I do I get the "am/pm" to be stored with the date and time so it looks something like this "2009-02-20 04:20:23 pm"?
View Replies !
After Date And After Time
I would like to make a memo script that once you have entered the date and time and note in a memo intto the database the memo is displayed once both date and time have passed. I dont want the memo to disappear until it is told to. I have an idea how to make it disappear, but I dont know what the syntax is for the sql for AFTER the date has passsed and AFTER the time has passed.
View Replies !
Time AND Date
i want to store the time in my field typ time. i DON`T want to store date and time in one field. in the field i see the time with an admin tool, but when i want to put out the value in an ASP page i get time AND date .how can i configure the field typ to store ONLY the time ?
View Replies !
About Date And Time
i have created a table using the following code: ------------------------------------------------------------------------------ create table tt(name varchar(10), enddatetime timestamp, startdatetime timestamp, difference timestamps); ------------------------------------------------------------------------------ after i have created, i insert the following into it: ------------------------------------------------------------------------------ insert into tt values('bob',null,'2006-10-1 12:12:12',null); ------------------------------------------------------------------------------ and i want to find the difference between the enddatetime and the startdatetime. so i tried the following: ----------------------------------------------------------------------------- select enddatetime,startdatetime, sec_to_time(unix_timestamp(enddatetime)-unix_timestamp(startdatetime)) as difference from tt; ------------------------------------------------------------------------------ but the value came out from the difference column was xxxxx:xx:xx *(where x is an integer). as you can see, the year,month,date and the hour are all mix up together(xxxxx). so i was wondering whether my code or my variable was wrong?? and by the way, how can i show the difference in terms of seconds?? like converting the enddatetime and the startdatetime into seconds and substract them together?
View Replies !
Date Time
what I want to do is very simple however it seems I'm having trouble figuring out how :D I got a date_time field in a table. I want to retreive all the records that match yesteday. Something like: select * from table where datetimefield = now() - interval 1 day HOWEVER because it's a date_time field (and I can't split it in 2 fields for other reasons), the above query won't return anything. Seems I could do a select * from table where datetimefield between yesterday at 00:00:01 and yesterday at 23:59:59 but I can't find the functions for that.
View Replies !
|