Struggling With Dates And Times!
I'm using MySQL 3.23 - I know it's old but it comes as default on Linux distribs and I just want something consistent between home, my ISP and work.
I want to work out the time difference between two entries on my database (I'm using PostNuke and have two posts which are stored as integers, ie unix times). I can see that there is now a datediff() and timediff() function but they don't work hence why I mentioned the version I'm using.
Can anyone tell me how to get the difference between two dates - I am assuming I subtract one from the other but don't know how to convert the result into something useful (like days and hours etc) because I'm not sure what the unix time is made up of.
I guess an easier version of that lot is : is a unix time just a second count?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Dates And Times
I have a field in a DB called "customerJobDate" which is configured to store full dates (ODBC dates) e.g. "2006-03-06 08:30:00". Now this does work i can update insert and delete the records perfectly, But if i query the DB asking for all dates that match 2006-03-06 regardless of the time (Date only) then the result returns 0 rows unless any of the dates in the column have 00:00:00 as the time. This works: 2006-03-06 00:00:00 This does not work 2006-03-06 08:30:00 I hope someone can help me as I am finishing this app and this is the only thing holding me back.
Dates And Times.
You can't have two timestamp columns in a database both with the default now(). - why I would want to is not the issue. You can't use the data and time functions, such as CURRDATE()/CURRTIME() provided by MySQL as defaults for date/time type columns. Is there a way to use something like 'select currtime();' as the default for a column? so my question is, how do I use ANYTHING other than one timestamp with the default value of now() for date/time defaults in MySQL.
About Dates And Times
I have form with drop down boxes, where folks enter dates and times, I have used implode and explode to format the dates, now I want to write those dates to mysql, I know mysql has its own date and time functions, is there a way to convert my php formatted dates and times into something that mysql will recognize and store as a time and date or does php have a function that will convert it and then allow it to be stored in date/time format in the database?
Who Do I Write Select With Dates And Times
i have to cols, date and time. who can i do, SELECT between (date 1,time 1) to (date 2, time 2)? for example i want to get the recordes between 2007-01-01 23:00:00 to 2007-01-03 03:00:00 ?
Struggling With 'updated'-NOW() Field
I try to learn SQL by figuring out things. I want to make a listing of all records that were changed in the last... 1, 6, 12 hours/days. I have a field called 'updated' managed like: UPDATE tablename SET updated = NOW(), .... WHERE.... I created a query like this: "SELECT * FROM tablename WHERE 'updated'
Struggling With Left Outer Join
got two tables: T1 - User, Date, Stuff T2 - User, Date, Other Stuff I want to be able to select rows from T1 based on User & Date, join those rows to the data in T2, so T1.User=T2.User AND T1.Date=T2.Date. Then I want to sort the results in T1.Date order I've no idea where to start ... anyone point me in the right direction?
Converting MS Access Dates To MySQL Dates During LOAD DATA INPUT ?
My insert code is below. The MySQL server is on my local machine and is version 4.1.22. I am exporting from an access table with 6 fields to a mysql table with those 6 plus 5 more fields. The main problem I am having SO FAR, is converting dates. The data file dates are formated like: 2/2/2006 0:00:00, 12/20/2006 9:22:05 Any ideas how to format those into mysql friendly dates? Also, how do I convert currency fields in the load data process? I know you use SET by what kind of formula? =========================================== LOAD DATA INFILE 'C:Documents and Settingspath_to_filedata.txt' INTO TABLE auto (field2, field3, field4, field5, currency_field6, field7, date_field8, date_field9) SET id = MD5(UUID()) FIELDS TERMINATED BY ',' LINES TERMINATED BY ' '
How To List All Missing Dates Between 2 Dates
I have a database which stored financial data daily exclude weekend, however sometimes i tend to forget to upload data into the database. How do i write a sql query that would detect the missing dates between from last updated date until the current date.
Stroring Dates Perior To 1 AD, BC Dates
I need to store some dates that can be BC, However I received a problem indicating Incorrect Datetime. I have read the documentation, and it says that Date&DateTime types can store from 1000-9999 AD, and Timestamp stores less year ranges. What other options do I have to store dates before 1000 AD !
List All Dates Between 2 Diff Dates
I have a database which stored financial data daily exclude weekend, however sometimes i tend to forget to upload data into the database. How do i write a sql query that would detect the missing dates between from last updated date until the current date.
Dates, Dates, Dates - Syntax Help Please!
OK, I have a MySQL table which contains, among others, a field called date which stores dates in the format YYYY-MM-DD HH:MM:SS. What I'd like to do is select a list of all the months present (without repetition), preferably in the format YYYY-mm
Appear 2 Times
i'm having this problem finding out the right sql query. i have two tables A & B the userid in table A appears as FK in table B i need to list userid that appear 2 times or less in table B which has a where clause column3='Yes' how do i go about it>?
One To Many Multiple Times
I have a 'links directory' database that currently contains 4 tables: category, subcategory, region and links. My links table contains company names and, among others, three fields catID, subcatID and regID. Each of these are related to primary keys in the other three tables, category (catID), subcategory (subcatID) and region (regID). My issue is that the records in the links table can be in multiple regions, multiple subcategories and multiple categories, but the way I have it designed, each record in links can only be associated with a single catID, subcatID and regID. Currently the only workaround I can think of it to have duplicate entries in the links table for a single company, but with every variation of catID, subcatID and regID. This will result in a very large table, but I cannot currently think of any better idea.
Upload Times
I need to upload 2 star catalogues to the mysql database. the first time i tried this i filled up the HD in 2 Days, my instructor mentioned that journalling was taking up most of the space and decided to remove-it. now, with journalling turned off, i have started re-uploading the catalogues, but have noticed a significant decrease in "write" speed. my question is, does journalling speed up writing data into mysql tables? i have roughly 180GB of data to upload, and it took me 4 days to upload 3GB's when last time it took me this time to upload 100GB.
Number Of Times
I have a query that grabs 500 rows from 1 field within 1 table. In this table. Each user will have 500 rows associated to them from within that table. So if there are 2 users then there will be 1000 rows. Each time 1 user executes the query, it grabs their 500 rows. If 2 users execute the query simultaneously, then this means that there are 1000 rows, all of which will be selected; 500 by one user and 500 by the other. If 3 users access the table simultaneously, then there are 1500 rows and so on. My question is how many users can execute this query simultaneously before we see performance loss?
Records Between Two Times
I have a table for a restaurant database with two fields open_time and close_time in TIME format. I want to be able to select all records that fall between open_time (when the restaurant opens) and close_time (when the restaurant closes). I have this query: Quote: Select hours_id from hours where curtime() between 'open_time' AND 'close_time'; It partially works, but its not working if the close_time is after midnight (i.e 1am = 01:00:00 in database). I can't figure out the issue with the difference between AM and PM.
Ordering Times
i have some vlaues in a database, they are 12 hour times, how would i go about sorting it so 12 comes before 1, as it is its going 1 2 3 4.... 12 etc etc, do i have to use a 24 hour time? then from there function it to show 12 hour when displayed
Comparing Times
I'm creating a voting system, and want to prevent people from cheating. Therefore I'm logging their IP, and the time they voted, and what I'm planning to do is have a script which will delete any records which have been in the database for say 24 hours. To get the length of time I was gonne use: HOUR(TIMEDIFF(NOW(),time))
Measuring Query Times
I have read a few posts here and see that some people have questions regarding the length of time it can take to perfrom their queries. I would be quite happy reaching that stage because at least I would know how long mine take. :| How can the time delay be forced to output? Using MySQL 5.0.
Subtract Two Event Times
I am trying to formulate a complex query to get some good info straight from SQL, rather than post-processing in XL. I have a table as follows: EventID Integer (key) ActionID Integer, 1 = event on, 2 = event off dtStamp Date I want to get the duration of each Event. I.e. I need, for each Event: dtStamp(actionID = 2) - dtStamp(actionID = 1) I was going to try: >create view EventOnTime as select EventID, dtStamp as EventOnDtStamp from EventLog where ActionID = 1; >create view EventOffTime as select EventID, dtStamp as EventOffDtStamp from EventLog where ActionID = 2; >select eventOnTime.EventID, eventOnTime.EventOnDtStamp - eventOffTime.EventOffDtStamp as EventDuration where eventOnTime.EventID = eventOffTime.EventID; ... but I can't create views with this version of SQL (server version: 4.0.20-standard-log)
Dump File Times Out?
I have a huge Access database (about 50,000) records. I use Access dumb to create a sql file which I can them go into phpmyadmin and import the records. Well, after a while the process times out. Is there a way I can import large amount of data into MYSQL without timing out? Also the access database that I convert over gets updated every week. I don't know which records get updated or added. Also the app I am using only works with Access so I can not completely convert over. Is there a way I can update the MYSQL without having to import that huge file again. Maybe something that will not override the records that are same just change the modifed ones and add the new records.
Call To Database Times Out
using ZenCart 1.3.7, and when it calls to the database after clicking on "go to checkout" it hangs and then returns the following error message: I get this message after clicking on "go to checkout" 2013 Lost connection to MySQL server during query in: [select sum(tax_rate) as tax_rate from (tax_rates tr left join zones_to_geo_zones za on (tr.tax_zone_id = za.geo_zone_id) left join geo_zones tz on (tz.geo_zone_id = tr.tax_zone_id) ) where (za.zone_country_id is null or za.zone_country_id = 0 or za.zone_country_id = '223') and (za.zone_id is null or za.zone_id = 0 or za.zone_id = '12') and tr.tax_class_id = '1' group by tr.tax_priority] 2006 MySQL server has gone away in: [select count(*) as total from sessions where sesskey = 'd60f1f220b761a5a176738c1a65de4b2'] Warning: Unknown(): A session is active. You cannot change the session module's ini settings at this time. in Unknown on line 0 I've checked with my host, and they are able to do a php call to the database just fine.
Adding 1 Year To All Times
suppose that dbX -> tableX id columnX 1 1190815874 2 1192975748 3 1196695027 4 1196796789 how can i add 1 year all value where year is 2007 ? my sql do not run UPDATE `tablex` SET `columnx` = DATE_ADD(`columnx`, INTERVAL 1 YEAR) WHERE DATE_FORMAT(FROM_UNIXTIME(`columnx`),'%X')) = 2007;
Slow Loading Times
It takes more than 30 seconds to load the phpmyadmin page. On a localhost server. It says Fatal error: Maximum execution time of 30 seconds exceeded in c:appservwwwphpmyadminlibrariesmysql_wrappers.lib.php on line 101 This sometimes also happens when loading my local website that uses MySQL. I've tried reinstalling, but it doesnt help.
Export Records Times Out
I try to export all records from my db about once a week. I use phpmyadmin and select all tables structure and data and export as file. Well the problem now is it always times out when I do this. The db only contains about 18 tables and maybe 20,000 lines of data. The tables average about 12 fields each. So now I'm exporting a few tables at a time. Is there something I can do to change this?
Left Join 2 Times
SELECT f.id as id, f.forum_name as forum, f.forum_desc as description, count(forum_id) as threads, u.name as mod FROM forum_forum AS f LEFT JOIN forum_posts AS p ON f.id = p.forum_id AND p.topic_id=0 LEFT JOIN forum_users AS u ON f.forum_moderator = u.id GROUP BY f.id Output: 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 'mod FROM forum_forum AS f LEFT JOIN forum_posts AS Does this query contain any syntax errors? Can mysql perform left join 2 times?
Ordering Results By Number Of Times They Appear
I'm not really sure the best way to explain what I want to do, so I'm going to make a really simple example to illustrate what I mean. Let's say I have a table with column "temperature". There are 5 entries that contain the word "hot", 3 entries that contain the word "medium", and 2 entries that contain the word "cold". However, these entries are not in any particular order. Is there a "SELECT * FROM" statement which will return the results by order of popularity in the following manner?: hot (5) medium (3) cold (2) I have a script I'm working on and I'm trying to figure out the best way to do something like this.
Select Same Row Multiple Times Using Column
I've seen this asked before and although someone answered that it is possible, they did not post the solution, so if anyone can enlighten me that would be helpful. Basiclly with table info name | quantity john | 3 anne | 1 will | 2 Return results john john john anne will will
How To Find Out How Many Times A Query Has Been Executed
How can you count the number of times your query has been executed? So I'm trying to set it up, so that I get a variable on every time someone views a review. I have two querys right now, but honestly don't really know what I'm doing. And I'm assuming I have to increment viewcount everytime that query gets executed. This query looks up the review:
Report Of Query Execution Times
Does mysql have a tool to record and report a list of all queries executed and how long it took to execute each query? If not can anyone suggest a tool I can use to do this? I've heard of mysql query profiler but does it capture queries from all sessions?
Trace SQL Queries Date/times
I have a web application connected to mySQL 4.1 database. I would like to know the date/time for the queries executed on mySQL DB when any operations performed from the UI. Is there any mechanism to trace the information related to any query updates happening on the DB when operations are performed from the UI.
Datetime And Timestamp Recording Different Times
I have a datetime field that records date and time. This field records when rec is created. I also have a timestamp field that records whenever the record is updated. I noticed that when i first create the record, the update time is about 3-5 minutes before the create time. The update time and create time has to be identical. How can one lag the other? Im executing sql from a php page.
Joining A Table Multiple Times
I was wondering if it was possible to join 2 tables on 3 different feilds, but I don't want the 3 feilds to limit my results... I'll try and explain: Table 1 = "offices" Table 2 = "employees" The offices table has the addresses of all the offices and 3 extra feilds "manager", "supervisor", and "employee". (these 3 feilds have a numeric value equal to the primary key in the employees table) The employees table has the employee information like address and phone number and such. I would like to write a query that would pull the office name as one feild, followed by "manager", "supervisor" and "employee". Currently I have this, but it only pulls the employee and I'm not sure how to get the manager and supervisor to be a part of the query: SELECT CONCAT(office.id_store, ' - ', office.storename) as offices, CONCAT(user.lastname, ', ', user.firstname) as fullname FROM office LEFT JOIN user ON office.empoyee = user.id_user
Mysql Result Times Over 15 Seconds
I am having problems with result times. I run a search from my website and it takes around 15 seconds to generate the mysql query and then 40 seconds to load the page.
MySQL Query Times Out From Page But Not Console...
The query works ok when executed from the console, but never executes from the any page. - When I use MySQL Administrator to view the threads this particular thread gets stuck on "copying to tmp table on disk"...
Calculating Time Difference In Minutes Between 2 Times
I have two columns in a table start_time and end_time (stored as datetime). I wish to work out the time difference in minutes between these two values. If the difference is 1hr 30 minutes I wish to get 90 (mins) I have tried: SELECT TIME_FORMAT(TIMEDIFF(start_time, end_time), '%i') FROM table ... This returns justs the minutes (e.g. 30) and SELECT TIME_FORMAT(start_time - end_time, '%i') FROM table .... no such luck.
Linking Table Entries Multiple Times
I have no idea how to handle certain kinds of relations between tables: I have a table called 'labels' and a table called 'artists'. Every artist belongs to at least one label, but could also belong to any higher number of them. How would I solve this in my database architecture? I discarded the idea of simply adding 10 columns called 'label1', 'label2', etc; Also I have found the ENUM and SET datatypes, but the possible values entered there should be set at table creation time which is also not quite what I'm looking for.
Which Is Faster In MySQL? Comparing Unix Times, Or DATETIMES?
I'm leaning towards using unix times inserted into my MySQL for ease of use in manipulating the data with PHP. I think this will be the final decision, which one would be faster? -- Mysql: * INT (4 bytes) * DATETIME (8 bytes) * TIMESTAMP (4 bytes) -- My PHP application does alot of querying from the database to compare specific data within TIMERANGES, so always, I'm querying with "time >" or "time <". My question is would doing the WHERE time query with the native MySQL DATETIME be faster, than doing a WHERE query with the unix timestamp?
Dates
I have a 'date' field, i.e. YYYY-MM-DD. I have a dynamically generated array, which I convert to a string of the form 1, 2, 3, 5, 7, 12 where the numbers represent months. If necessary, I can make the string have leading zeros for one-digit months (so 1 -> 01, 2 -> 02) etc using PHP. What I want to do is select all rows from a table where MM from the date field is in the array. Is the following correct? (I can't try this right now as I'm not able to access the code/DB from here) SELECT *, DATE_FORMAT(dateField, '%m') AS dt FROM aTable WHERE dt IN(01, 02, 03, 04, 07, 12)
Dates In SQL??
I'm having some trouble with dates in MySQL. I'm developing a site that has an area for news. I've created a table that's called NEWS and it has 3 columns: id, date, news_text. For the date I've given these properties: datatype:timestamp, default:current_timestamp. The problem arises when I retrieve the news. I want the date to be printed as well in the form of YYYY-MM-DD, but I guess due to the current_timestamp, I get YYYY-MM-DD HH:MM:SS. 1) Is there a way to ommit the time?? 2) How can I change the format and make it DD-MM-YYYY??
BETWEEN X AND X For Dates
I'm trying to find all records that fall between two dates. BETWEEN only seems to be for integers so I was wondering there was a similar construct for dates.
When Should I Use Int For Dates?
I'm thinking about storing dates in my databases as unix timestamps in int fields. Since I use PHP I'm thinking it would be convenient to have timestamps rather than datetime fields. But someone told me I can't store dates earlier than 1970 as timestamps. So do I have to decide from application to application if I expect to be using dates earlier than 1970, or is there a way around this rule?
Dates Between Dates
Is it possible to query dates between two dates straight from mysql database? Example: I have two dates in my database that function as start of an event and end of an event. I can get results when I seek an event that starts 2006-07-30 and ends at 2006-08-06 with following sql-query: select eventid from database where (startdate between '2006-07-30' and '2006-08-06') or (enddate between '2006-07-30' and '2006-08-06'); Or by using any date values that go "over" the specified dates in database. Problem is that I would like to get the event also when it's active between these dates. Like from 2006-07-31 to 2006-08-02, but no result will be returned with this example query: select eventid from database where (startdate between '2006-07-31' and '2006-08-02') or (enddate between '2006-07-31' and '2006-08-02');
BETWEEN Two Dates
I am making a calendar function in php and i need to know if an appointment already exists between two dates. I am trying to use some like below but with no avail, any other ideas? SELECT id FROM appoit WHERE UNIX_TIMESTAMP(day) BETWEEN '$date' AND '$until' AND room='$room' Note: `day` is actaully stored as a datetime value $date is the wished start date and time in the format of php's mktime $until - as above but when the appointment will end
Dates Between
I want to write a query that gets all the dates between 2 specific days (not the difference between them).
Dates
I'm migrating my site form mssql & asp to mysql & php and I'm having a problem with this sql sintax. What I do is select a value between 2 dates and show the results but I cannot figure how to do it in mysql. My mssql sintax is: $sqlstm="SELECT * FROM vidas_pasadas where fecha1<=#".$fecha."# and fecha2>=#".$fecha."#"; How should the mysql sintax look like?
Dates Comparison??
I'm trying to find people from my db based on a given min_date and max_date using: SELECT . . . WHERE birthdate BETWEEN '".$dd_min_age."' AND '".$dd_max_age."' but if a range is specified there are no results returned. If I choose though the same date for min and max then I get the corresponding results.
|