Search On Dates?
I have 2,000 stories saved in a database (Not my DB) and I want to perform a search on the section of story and the date it appeared on the website.
The trouble is the DB is dodgy and dates are saved in a format like:
2007-1-8 //Today
Ie
YYYY-M-D
Now what I want to do is perform a MySQL statement whereby I perform a search on the date in this format:
2007-1-8 //Today
Ie
YYYY-M-D
IE: "Y-n-j"
And then my SQL finds the date I asked for, but then
- Checks it’s not greater than today’s date (NOW) by using unix_timestamp on both the appreared field and published field.
And then output all the results to the screen.
Now I thought this may work:
PHP
$sql = "select id,headline,appeared from news_stories
where section = '$searchstring' AND
date_format('$appeared','%Y-%m-%d') =
date_format(appeared,'%Y-%m-%d') AND unix_timestamp(published) <=
unix_timestamp(now())";
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Search Between Dates
I thought I had this figured out but I guess I don't here is what I have. SELECT * FROM servers WHERE server_id=".$_GET['server_id']." AND DATE_FORMAT(serve_date, '%m/%d/%Y')>= ".$_GET['datefr']." AND DATE_FORMAT(serve_date, '%m/%d/%Y') <=".$_GET['dateto']." It works but when I enter dates 02/02/2007 to 03/01/2008 I get 02/25/2005 and 02/23/2008 returned. How come the 2005 showed up?
Search Between Dates
i have the following query ,PHP Code: $query_january = $db->query("SELECT * FROM stock_vehicles WHERE purchasedate BETWEEN '2005-01-01' AND '2005-01-31'"); which should as far as i know search between January the 1st and January the 31st but it seems to pull all entries from the database.
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
Search: Remove Quotes From Database For Search
I am making a book site and currently in the database are book titles likes "John's Trip" and "Peter's new bike". I have a search function where the customer can type in "Peter's" and it will bring up everything with "Peter's" in it. But i was wonderind is there any way i can search for "Peters" and "Johns".
I Have A Search Form To Search Through The DB.
I have a DB with 50,000 entries. I have a search form to search through the DB. If the recno=30123456 and you search the recno, you get that one file. what if i want a query that searches alll recno's that contain 30?? Can I do that using mysql or do I need to program that in my java app?
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.
Recurring Dates
I'm trying to make a calendar with events that can recur daily, weekly, or monthly. I think I can do it like so... any recommendations or improvements? SELECT * FROM drinks_e WHERE (drink_e_date = CURDATE()) AND (recurring = 'once') OR ( (DATE(drink_e_date) <= CURDATE()) AND (WEEKDAY(drink_e_date) = WEEKDAY(CURDATE()) AND (recurring = 'weekly') ) OR ( (drink_e_date <= CURDATE()) AND (DAY(drink_e_date) = DAY(CURDATE()) AND (recurring = 'monthly') ) OR ( (drink_e_date<= CURDATE()) AND (DAYOFYEAR(drink_e_date) = DAYOFYEAR(CURDATE()) AND (recurring = 'yearly') )
Interpreting Dates
I have dates stored in the database in a field called start_date, in the format yyyy-mm-dd. What sort of query conditions can I use to select only dates:Falling during the current month (i.e. July) orFalling during any given month and year (i.e. September 2007) orFalling over the next x months?Is it possible to select these only using SQL queries?
Count Between Dates?
I want to run a SQL query whereby I count how many records are in a database table ie: PHP <?php $query = mysql_query("SELECT * FROM dbtable"); $result = mysql_num_rows($query); echo "$result "; ?> But how could this be modified to count ALL stories from a weekly period, but not specify specific dates - ie find out the total entries for: - Every time it is Sunday and the time is 00:00 till - Every time it is Saturday ending at 23:59 So this week I would be counting all dates between Sunday 25th February at 00:00am to Saturday 3rd March at 23:59pm So when it turns: Sunday 4th March at 00:00 a new count will begin without specifying the dates?
Handling Dates
Hi I have a table that I’m going to use for assigning equipment to a task since its going to be used for a simulating a company I need to filter out Sundays and non workable hours. I calculate the time the equipment will be used by multiplying the number of units to be produced by the time it takes mo make one, but I also need to add Sundays and the time that the factory isn’t producing, work hours are from 8am to 5pm. I’m really lost and don’t know to this, any help will be greatly appreciated. #---------------------------- # Table structure for orden_produccion #---------------------------- CREATE TABLE `orden_produccion` ( `Id` int(12) NOT NULL default Ɔ', `ProductID` int(12) NOT NULL default Ɔ', `TransaccionID` int(12) NOT NULL default Ɔ', `EquipmentID` int(12) NOT NULL default Ɔ', `StartDate` date NOT NULL default ��-00-00', `EndDate` date NOT NULL default ��-00-00', `Quantity` int(8) NOT NULL default Ɔ', PRIMARY KEY (`Id`,`IdProducto`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; The end date is what i want to calculate
How To Get Records Between Two Dates
In database I have stored dates in ��-00-00 00:00:00' format. And from user I am getting dates in 'mm/dd/yyyy' format. 1- How can I get records from database between user entered dates.
How To Get Data Between The Two Dates?
i'm using the between operator to list all the transaction between the dates and it's working fine. But i want to list all the transaction from a table including the startdate and the enddate.
Grouping Dates Together Then Sum()
Can anyone show me how to add the amounts together but by month. So all the month's of 12's added to gether and all the 11's (months). mysql> select * from date; +----+------------+---------+ | id | date | amount | +----+------------+---------+ | 1 | 2006-12-25 | 100.00 | | 2 | 2006-12-20 | 1456.34 | | 3 | 2006-11-04 | 400.00 | +----+------------+---------+ 3 rows in set (0.00 sec)
Working With Dates
After taking a break from this project for a bit I find myself confused about how to pull specific date periods from a database. The timestamps are stored in UNIX format. I'm creating a report builder to pull details about issues that my techs have entered (ISP support center). I can pull reports from calls entered today or yesterday, but getting them from say, mon-fri of last week is throwing me for a loop. Can anyone point me in the right direction? This is what I have thus far: //echo "DateRange: ".$daterange."<br>"; // begin building our query $query = "SELECT * FROM issues WHERE "; // the value passed in date range is how we modify the date lookup in our SQL query if ( $daterange == "today" ) { $timestamp = strtotime("today"); $query .= "DATE_FORMAT(CURDATE(), '%Y%d%m') = FROM_UNIXTIME(issue_submitted_date, '%Y%d%m');"; } else if ( $daterange == "yesterday" ) { $query .= "DATE_FORMAT(CURDATE() -1, '%Y%d%m') = FROM_UNIXTIME(issue_submitted_date, '%Y%d%m');"; } else if ( $daterange == "thisweek" ) { $query .= "DATE_FORMAT(CURDATE() -7, '%Y%d%m') = FROM_UNIXTIME(issue_submitted_date, '%Y%d%m');"; } else if ( $daterange == "lastweek" ) { $query .= "DATE_FORMAT(CURDATE() -14, '%Y%d%m') = FROM_UNIXTIME(issue_submitted_date, '%Y%d%m');"; } else if ( $daterange == "thismonth" ) { $query .= "DATE_SUB(CURDATE(),INTERVAL 1 MONTH) >= issue_submitted_date;"; } else if ( $daterange == "lastmonth" ) { $query .= "DATE_SUB(CURDATE(),INTERVAL 2 MONTH) >= issue_submitted_date;"; } else if ( $daterange == "thisyear" ) { $query .= "DATE_SUB(CURDATE(),INTERVAL 1 YEAR) >= issue_submitted_date;"; } else if ( $daterange == "lastyear" ) { $query .= "DATE_SUB(CURDATE(),INTERVAL 2 YEAR) >= issue_submitted_date;"; }
Subtract Dates
I am trying to subtract two dates(c.return, c.reserved as shown below) in an older mysql version in which new date functions doesnt work... so far i have this query working fine...but i was looking for an efficient one...anyone has any suggestions on the efficiency improvement to this below query...
Count Dates
Have a field (date_applied) that is a timestamp. I format the date with date_format and %m/%e/%Y...I want to count all occurrences of any date. So let's say you have this: 3/12/2005 3/28/2005 3/28/2005 4/1/2005 4/1/2005 4/1/2005 4/11/2005 I'd like to see this: count | date_applied 1 | 3/12/2005 2 | 3/28/2005 3 | 4/1/2005 1 | 4/11/2005 Any help would be appreciated.
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.
Using Dates To Query
I have a table with a field for each record with a date in it. I want to get all records before September 12,2000 but I don't know what the query should be.
Use Between In Dates Query
can I safely use between with dates as in: select * from table where CURRENT_DATE() BETWEEN LASTMONTHDATE AND NEXTMONTHDATE
Dates In Querys
I'm returning the month from a datatime stamp in a mysql query using the following: MONTH(theDate) AS tMonth Only problem is, if the month is before november, it doesnt not return the preceeding 0, so for example.. september I only get 9 not 09. Is there any way in the query to define this?
Compare Dates
Using mysql 4.0, which doesn't support DATEDIFF I'd like to compare two dates and check if the difference is 6 weeks or greater. How can I do this?
Difference In Dates
I have a date-field in a mysql-table and I want to make the difference between this date and the date now. I've tried this SELECT `table`.`datefield` - now( ) AS difference FROM table; The result I get is something crazy. For example: - difference between now (26/06/2005 21:18) and 24/06/2005 gives me -20050606161211 - difference between now and 16/07/2005 gives me -20050606161119 Not really something usefull I think... I would like the difference in days, so 24/06/2005 - 26/06/2005 gives me -2 days.
Populating Dates
I am trying to populate all the dates from 2003 to 2006 in a table with one column - "Dates". How may I achieve that?
Formatting Dates
I've got a script that is designed to print entries in a table. This script uses a query: $query="SELECT * FROM entries ORDER BY time"; $result=mysql_query($query);entries: table time: datetime field in table And then a row count to print every entry: $num=mysql_numrows($result); $i=$num - 1; while ($i > -1) { $title=mysql_result($result,$i,"title"); $entry=mysql_result($result,$i,"entry"); echo "$title<br>$entry"; $i=$i-1; } Now, I would like to have the datetime field associated with every row printed as well, but I don't want it just printed as is, I can achieve that with: $time=mysql_result($result,$i,"time"); echo "$title<br>$time<br>$entry"; But what I get looks something like: 2006-15-06 20:56:34 I'd like to get that more readable, and I understand the different symbols for each different way to display the date, but I don't know how to make this apply to the printing of the datetime field from each entry.
Difference Between Two Dates
1) I have mySQL 3.23 installed. I have a record with two date/times fields in YYYY-MM-DD HH:MM:SS format. How do I find the difference between those two date/times? (I would also like to know it with seconds left off.) 2) Let's say I have two records each with a date/time field in YYYY-MM-DD HH:MM:SS format. How do I find the difference in date/times when each field is in a different record?
Comparing Dates?
i have an 8 digit date string that i want to compare to a column of type 'date' in a MySQL db. the 8 digit string is in the format 'CCYYMMDD'. the question is: do i need to put it into the 'CCYY-MM-DD' format in order to get correct output from the datediff function, or can i simply leave it how it is?
Difference Between Two Dates
I am trying to write a query that will calculate the difference between the start and end date of a record, and then sum the results. The problem is that I want to ignore portions of the periods encountered if the overhang, so for January 06, if a record has start 15/12/05 and end 06/01/06 the answer would be 6 days.
Comparing Dates
I have a problem with me. I am describing the whole situation. I have a table, the structure of the table is as follows: Table Name: Announcement FieldName Data Type(Size) Announcement Varchar(50) St_Hr Decimal(10,0) St_Min Decimal(10,0) St_Day Decimal(10,0) St_Mon Decimal(10,0) St_Year Decimal(10,0) End_Hr Decimal(10,0) End_Min Decimal(10,0) End_Day Decimal(10,0) End_Mon Decimal(10,0) End_Year Decimal(10,0) The data stored is: Test Announcement,10,20,6,10,2005,11,0,8,10,2005 Now, I have to write a query to retrive announcements after filtering them as per the mentioned Starting and Ending Date & Time. The condition should use the local date and time.
Difference Between Two Dates
I need the elapsed time between posting of an item and the current local date. I have a table, with timestamp, want to pull each entry and calculate the elapsed time for each entry. ie, how old is this posting?
Displaying Dates
I need to be able to perform 12 queries (one for each month) so that the first month it displays is the month that it is, ie. if i visit the site in June then June will be the first month displayed and May will be the last month. I know that I can DATE_FORMAT NOW() and get the actual month right now, how do I get the other months using this kind of method?
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.
Subtracting Two Dates
I have to subtract two dates and get the results in hours, minutes, and seconds. It seems like such a simple question, but I can not get things to come out the way I want them to. I am not on 4.1.1 yet (4.0.18) so I can not use the new functions. Any suggestions?
Working With Dates...
How would I finish a query like this: SELECT * FROM table WHERE datetime_field BETWEEN NOW() AND <tonight at midnight> I'm not sure how to calculate "tonight at midnight" in a format that can be compared to the result of NOW(). Any ideas?
Days Between Dates
I need to know how to get the number of days between two dates using MySQL 3.2. I went over the manual before posting and found (DATEDIFF) but that can only be used with version 4.1 witch is still in alpha. Can anyone solve my problem?
Importing Dates
How do you get it to import if the text file has different date formats. specifically MM/DD/YY and MMM DD YYYY example 06/22/05 and Jun 22 2005 ?
Summing Dates
I have a table that has two columns, starttime and endtime.Usng this query I can get the time durations between each start and endtime for each row: SELECT TIMEDIFF(endtime, starttime) from playertabletime where playerid=37 and starttime > DATE_SUB(now(), INTERVAL 1 DAY); Using this I can sum times together: SELECT SEC_TO_TIME( SUM( TIME_TO_SEC( `a_time_value`) ) ) AS total_time FROM playertabletime; But in ONE query I want sum all the timediff durations returned from the first select to give me one total duration.Any ideas?I have tried copying the first query into the second but this is not valid SQL.
|