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 Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
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)
Sorting Time Values
I have been trying and trying to properly sort records through a mySQL query. I have hour, minute and AM/PM values stored separately in a database as varchars. I'm trying to concat those, cast them to a time value and sort them. I have found that it sorts some properly but other it does not. The following query: CAST(CONCAT(hour, ':', minute, ' ', ampm) AS TIME) AS myTime ORDER BY myTime Sorts some results like this: 10:30 PM 8:30 PM 9:30 PM But other are perfect: 10:00 AM 11:00 AM 12:00 PM 1:00 PM 2:00 PM 3:00 PM 4:00 PM 5:00 PM These exact results we part of the same recordset. Can anyone help me with this?
Mysql Date Time
This is probably an easy one but i cannot seem to solve it, what I have is a database with a lastlogin datetime field in the form: 2005-01-17 00:14:30 I need to do a select on each entry to find the number of rows later than the date of the current row datetime, as I have users that log log in at different times. I tried something like in a loop but this does not work select count(*) as total from user_table where (NOW()>DATE_ADD(LastLogin, INTERVAL 0 DAY)) and iUserId != '$iUserId'
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.
MySQL Date/Time Format?
My hosting company has a utility which allows me to dump the tables of a MySQL database in csv format for Excel. However, I can't figure out how to translate the numbers in date/time fields.
Set Mysql Sever Date/time.
The serer time in my mysql is messed up: CODEmysql> select now(); +---------------------+ | now() | +---------------------+ | 2006-12-07 16:14:19 | +---------------------+ 1 row in set (0.00 sec)
Change Date/time Stamp In Mysql
I'm moving a few posts from an old forum over to a new database. Not too much so I'm doing it manually. Queation is, how can I chnage the new datestamps to match the old? For example I have a post that is dated August 19, 2007, 01:36:14 PM in the old forum IN the new entry it show the date showing is: Oct 01, 2007 09:11 in the post and 1191247874 in the database. (the day and time I enter it) Is there a formula by which I can convert some of the dates on these old posts so they match the original?
Date/time Field Update Only Date
I have a field(tmMessage) in a table, it's a date/time struct. it looks like "2003-09-21 15:52:35" All I want to do is change the date in this field. I want the time to stay the same.
Date/time Field Update Only Date
I have a field(tmMessage) in a table, it's a date/time struct. it looks like "2003-09-21 15:52:35" All I want to do is change the date in this field. I want the time to stay the same.
Date And Time
I am having so much trouble formatting and checking against date and time; I think my query is simple this time. The following query does not work for me: Select ........ from ..... where ... and h_date = curdate() AND s_time > now(); I am just trying to check columns in tables where hire date is today and start time is greater than now. Please note, h_date is of DATE data type (Default) i.e. (yyyy-mm-dd) and s_time is of TIME data type.
Date And Time
can someone explain me the avantage of using date and time, and also can = i set time + XX minutes??
UTC Date/time
A data file I am trying to import has the date/time field in UTC format: YYYYMMDD HHMMSS+0. When I define my column field as datetime and import I only see zeros in all positions. Can MySQL import data that are in the UTC format and if so what data type or command should I use?
SQL Date Time
I've been having trouble trying to figure out the best way to select only the rows with timestamps within the last X amount of hours, days, weeks, months. So I guess my SQL statement in plain english would be: Give me all the rows that have a timestamp between NOW and X days/months ago and count how many times a row was submitted per hour/day/week/month within those rows. I'm pretty sure this is possible but I can't seem to wrap my brain around it.
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?
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.
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 ?
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.
Date & Time
i want to ast if i insert into table the value of now() in a datetime formated column does tha value it inserts if from my pc or from the server?
Subtract Date And Time
is there a way that I can subtract date/time in MySQL? For example I have this dates and I want to know the number of hours between this dates: I want to perform 2006-12-05 22:00 - 2006-12-07 08:00. Can this be possible in a mysql query? $date1= '2006-12-05 22:00'; $date2= '2006-12-07 08:00';
Date And Time Functions
I have been having problems using date and time functions in PHP. I am trying to design a schedule with a Calendar. I tried to use the following line of code to output the current month i.e. February. The line of code I have used is this : $month = mysql_query("select monthname(curdate( ))"); I am getting the following output from this: Resource id#6 why I am getting this output and are there alternative ways of getting the information I need.
Time Left Until A Specified Date
Using MySQL and php I need to be able to return the number of days, hours, mins and secs from the current date and time to a stored date and time in a table. Is there an easy way of doing this?
Date/time Function
I need to write a query which looks for certain criteria, then returns all rows which occur 0-30 seconds after. Can you please help with a generic query to accomplish this?
Created Date/Time
I would like to keep a row in my record that contains information on when the record was created and one when the record was last updated. What is the easiest way to go about doing this in MySQL?
Need To Include Time With The Date
I have a table called 'date_accessed' ... When I query that table for the date, how do I include the time along with it? Here is my query: SELECT user_agent, ipaddress, date_accessed FROM access_tracker;
Date/Time Format From CSV
I have a rather large csv file that includes many dates that I would like to import into MySQL. The problem that I am having is that the dates are DD/MM/YYYY HH:MM:SS, and MySQL does not accept them in its YYYY-MM-DD HH:MM:SS format. Any ideas how to convert this properly?
Date/Time Issue
I am very new to MySQL. I have used other databases before so I am trying to figure out how to do things I have done before. I want to create a table with a column of type DATE. When a row is inserted in the column I want the date the transaction took place to be inserted as the default in the column. I have tried a couple of things, but everytime I execute anything like: SELECT CURDAT (); MySQL reports Error 1146 Table mysql.proc doesn't exist. What have I not setup correctly? Same thing happens when I execute: SELECT VERSION (); I am using version max-5.0.18 on a Linux system.
Sort Date And Time
I have a simple question about sorting records based on seperate date and time fields. Take the following example query: SELECT some_id FROM datatable WHERE date >= '2007-01-01' and time >= '05:00:00' This returns all of the records with a date greater than 2007-01-01 and then reduces the records to only those with a time greater than 5:00. I want all records after 2007-01-01 5:00.
Date Time Question
first post: Hello, I'm trying to show what users are currently logged in on my site. what I've done is update a timestamp everytime they hit a page. what i want to do is select users where the current time Now() is within 15 minutes of the timestamp, to see if any users are on. but I'm not sure how to do this. any ideas? examples would be grate, I haven't done any asp in a long time. thanks in advance for you time! -Ken second post: ok, i've tried this, SQL = "Select user from accounts WHERE DateDiff(n, Now(), date) < 15 ORDER BY user" but i'm getting an error: ADODB.Recordset.1 error '80004005' SQLState: 42000 Native Error Code: 1064 [TCX][MyODBC]You have an error in your SQL syntax near '(n, Now(), date) < 15 ORDER BY user' at line 1 /admin/date.asp, line 6 also i'm using MySQL as the data base.
ORDER BY Date And Time
I am using php to extract variables from a MYSQL database that get loaded into a calendar application. Most everything works great. The only problem occurs when more than one event occurs on the same day. The event date and time are stored as separate variables in the database, thereby making it difficult to ORDER BY date and time. The result is that all of my events appear on the proper day, but they do not appear in chronological order. Is there a way to order by date and time? I currently have the following: Code: $SQL_Query = "SELECT eventID, eventDate, startTime, endTime, title, description, linkName, hyperlink FROM events ORDER BY eventDate";
Conditionals With Date/time...
I am trying to figure out how to use conditionals with date/time using PHP with MySQL. For instance i want a time limit on my site to restrict people clicking a link within so many minutes. So for example if they click the link once thats fine, but if they do it again say within the next 5 minutes i want one output, but if they wait the alotted 5 mins then another output.
Server Date Time
I have mysql server running in one machine. I have a query in my program 'SELECT CURRENT_TIME', it will retreive the system time. I installed my program in the client machine and it is connecting to the mysql server. If i execute the SELECT CURRENT_TIME, it is giving the client machine date and time. How can i retreive the server machine means on which mysql running, its date and time from the client machines.
Time And Date Fields
I have a form which insert data into a MYSQL table. In this MYSQL table I have a field called "DateEntered". Is it possible to have this field automatically updated with the current date when the form is submitted. What do I need to do in Mysql or on the html form?
Order By Date AND Time
I have two fields in my database... DATE > YYYY-MM-DD TIME > HH:MM:SS I want to order by date AND time, how can i go about this without making a TIMESTAMP table using the UNIX timestamp??
Need SQL To Calculate Difference Between Two Date/time
I need difference between two date not only in terms of day or hour or minute or second as outputted by following stmt. SQL SELECT TO_DAYS(NOW()) - TO_DAYS(��-09-16 11:45:00') AS diff_in_whole_days, ROUND((UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(��-09-16 11:45:00')) / 86400, 1) AS diff_in_days, ROUND((UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(��-09-16 11:45:00')) / 60 / 60, 1) AS diff_in_hours, ROUND((UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(��-09-16 11:45:00')) / 60, 1) AS diff_in_minutes, UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(��-09-16 11:45:00') AS diff_in_seconds; But I need the difference by days and the remaining hours, and remaining minutes and so on as shown below example: Difference bet 2007-09-17 15:45:14 and 2007-09-16 11:15:00 is 1day 4hr 30 min 14 sec. I need these all in sql statements for this requirement.
Select Date Ignoring Time
Im using a datetime fields eg. "2006-08-07 16:01:09" and I want to select dates... eg. "select * from mytable where mydate="2006-08-07" ignoring the time.
Find Date And Time Of Last Update
I inherited a server running MySQL 4.* from a previous developer. Now, the records on this database might be what I want, or they might just be test data. I think my only chance of finding out if this is the real thing is to find the date and time of the last insert into the database.
Indexing Date / Time Fields.
If we have a date/time field and are doing frequent queries WHERE {date/time field} BETWEEN TimeA AND TimeB Does it make sense, query speed wise, to create an index on the date/time field? The reason I ask is that TimeA and TimeB are significant down to seconds. My *assumption* is that with a large amount of data scatter very few records will contain duplicate date/time points. And that under these circumstances, indexing will be of little value since every date/time point will need to be examined in detail. Date/time fields are actually floating point numbers after all. In other words, the assumption I am making is that if most of the data in a field is unique, then indexing will yield little or no query performance benefit. Is my "assumption" valid? Would an index on the date/time field speed up this type of query?
Date And Time Stamp A Changed Row
I am about to declare a table with 20 columns. How do I create 4 more columns: 1. current Time 2. current Day of the month 3. current Month 4. current Year Such that: a. These 4 columns are not editable by the user. b. Whenever a row is updated/inserted/replace/etc. then these 4 columns in that row are automatically updated by the system accordingly.
Select Date And Time In Same Column
I have table called mytable and there I have column named time example: time 2006-07-10 10:28:06 2006-08-18 20:48:22 2006-09-15 12:11:41 2006-10-12 23:06:02 is there any possibles that I can make query example: SELECT *FROM mytable WHERE date BETWEEN 2006-07-10 AND 2006-09-15 AND time BETWEEN 10:28:06 AND 12:11:41 My point is can I make query where I first find between date and after that I make query where I find between time when information is in the same column?
Date/time Field Type
I want a field to automatically record the date/time each time a record is written to the db. Do I want that field to be of type DATE, DATETIME, TIMESTAMP…? My book is less than clear.
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?
Working Wit Date/time Values
I'm using the following query: Quote: SELECT * FROM IT_event_cal WHERE '$date' BETWEEN start_date AND stop_date Where start and stop_date are of type date/time (0000-00-00 00:00:00). For this particular query, I'd like to match a particular date (0000-00-00), and any time. How can I make the time part a wild-card value?
Inserting Date/time From Text File.
I have a text file I'm inserting into my mysql database. However, the text file contains a datetime field. I'm using phpMyAdmin to speed up the process. is there a way that I can set up the insertion of the file to contain the date and time as it appears in the text file? Right now when I insert the data, all I'm getting is zeros. I know it's possible from the command line. However, I do not have access to the command line on the production server.
Select Rows From Date Not Time In Where Clause
I am trying to select all the rows that where entered today and I have a datetime type column to store the date data in. How can I specify in my where clause to select where datecol=today and not have to specify the time? If I do where datecol=<?php date('Y-m-d'); ?> its not working
GROUP BY Date With Variable Is Unix Time
I am saving the Unix time every time a record is created in a field called "Time" and would now like to write a report to group on Date ... is there a in-built function to do this .. SELECT * FROM tblTemp GROUP BY [Date] ?
Combining Date And Time Fields Into A Datetime Field
I have a table with separate Date and Time fields. Is there a way to either: 1. Convert the date and time fields into a combined datetime field? or 2. Create a datetime value in the select statement so I can select all records before a given date and time?
|