Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    MYSQL


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Compare Datetime Field With Todays Datetime


How do I compare a datetime field in the database with todays datetime...

Is it:

if rs("fieldname")<>getdate() then
....
else
(gotto set a cookie here)
end if

Somebody suggested I use cdate...what is tht for..is it to make sure they are both in the same format or something.. if so how do I use it?




View Complete Forum Thread with Replies

Related Forum Messages:
How To Compare A DATETIME Field With A TIMESTAMP
How do I compare a DATETIME field with a TIMESTAMP one.

View Replies !
DATETIME Compare/subtraction
--0-930715088-1061086093=:22602
Content-Type: text/plain; charset=us-ascii

I'm having trouble understanding the MySQL docs on how to subtract two DATETIME values. I have two tables that have a DATETIME column. In my SELECT I am doing a JOIN to bring in both sets of rows. What I want is to subtract the DATETIME values to determine the number of seconds between their time. In the WHERE clause I also want to filter the selected rows if the difference in the DATETIME values is less that 900 (seconds).

View Replies !
DATETIME Compare / Subtraction
I'm having trouble understanding the MySQL docs on how to subtract two DATETIME values. I have two tables that have a DATETIME column. In my SELECT I am doing a JOIN to bring in both sets of rows.

What I want is to subtract the DATETIME values to determine the number of seconds between their time. In the WHERE clause I also want to filter the selected rows if the difference in the DATETIME values is less that 900 (seconds).

View Replies !
Adding Up DATETIME Field
i'm struggling with updating session expire times in my login table.

Can you tell me, how to correctly add an amount of seconds (after that
the session expires) to a datetime field?

when i do the insert for a new login, or an update, the expire field
will alway end up containing zeros Code:

View Replies !
Datetime Field Math
I need the most optimal way to determine if the value of a datetime field is between the current time and 24 hour before current time. I have tried the subtime function in several ways, and can't seem to get it to work.

View Replies !
Set Default Value For Datetime Field
How can I set a datetime field to have a default value of the time the record is inserted?

View Replies !
Default Value For DATETIME Field
I am trying to install a WordPress blog and the install script is failing as several of the tables contain a declaration like:

Code:

my_field datetime NOT NULL default '0000-00-00 00:00:00'

I am getting the message "Invalid default value for 'my_field'". Is there is a setting I can change to allow for this declaration, bad as it may be?

View Replies !
Datetime Field Problem.
I need to have a datetime field that auto-updates itself in the format yyyy-mm-dd hh:mm:ss.

Because of the formatting required I cannot use the timestamp field type. If I create a datetime field with the default value of now(). All I get is 0000-00-00 00:00:00.

Is there a way to accomplish this WITHOUT passing the update through code. Meaning have the database update the record automatically and not have to do this through an update statement?

View Replies !
Comparing DateTime Field To Now()
I am trying to have a select query which compares a Datetime field to the current date/time, Now(). Basically I want something to this effect:

SELECT Name FROM Lists WHERE expiration > 'Now()'

Expiration is a datetime field. The problem is It returns every name on the list except for ones with a value of 0000-00-00 00:00:00 whether or not the date has passed already. I have tried many other things including but not limited to

SELECT Name FROM Lists WHERE datediff(expiration,'Now()') > 0
SELECT Name FROM Lists WHERE timediff(expiration,'Now()') > 0
SELECT Name FROM Lists WHERE datediff('expiration','Now()') > '0'

and many other variations on those. The above 3 just returned a null recordset. How can I make this work?

View Replies !
Upgraded To 4.0.22 Now Datetime Field Is Different
We will be replacing an older server which is running mysql 3.23 and figured we would upgrade mysql apache and php. Most everything seems ok except for our helpdesk software (written in house) in php. It calculates the difference between two datetime columns so we can see the time span of when a ticket gets updated. With the new version it fails and shows me an error like this: date1 has to be >= date2 in calcDateDiff(1099810800, 1099810995). Date2 is the date when the ticket was submitted, and date1 is when the ticket was last updated.

With the newer mysql it seems to add a hidden value when the ticket is first created which causes the error. Depending on the function I use to calculate the difference it will return a number like -23:21:35 which is the approx. time since midnight and it was about 11:23 PM when I filled out a test ticket.

After I update the ticket it adds the datetime stamp and everything computes just fine.

I am not sure if this a mysql quirk or a php quirk since both were updated to newer versions.

Could someone explain what might be the difference between the datetime fields in the 2 versions and how I might fix the problem if possible?

View Replies !
Searching DateTime Field
I'm having a bit of trouble getting this to work. What i have is a DateTime field in a table and need to pull the records for only a particular day (based on a variable passed through). I looked on the MySQL website and found the date and time functions but it states the following,

DAYOFMONTH(date)
Returns the day of the month for date, in the range 1 to 31:
mysql> SELECT DAYOFMONTH('1998-02-03');
-> 3

Now how would i translate that into a workable PHP query? I tried the following with no luck,

$Query = mysql_query("SELECT *,date_format(date, '%M, %d, %Y ( %r )')as date
FROM $Table_diary WHERE DAYOFMONTH('date,$Day') && MONTH('date,$month')")
or die(mysql_error());

View Replies !
How To Get Date From DateTime Field
my Login field is in Date n Time format---->6/12/2006 02:30:25pm

And in my query, i juz wan to get the date wic is 6/12/2006.. how to write the sql?

View Replies !
Datetime Field Default Now() Fails
I have a mySQL database table with a column field datatype of datetime that I set up in the original create table statement like this:

create table nnet_usermetadata (
....
nnet_record_entered datetime default 'now()'
)

However, upon execution, each time a record is entered into nnet_usermetadata the results are:

00-00-0000 00:00:00

Is there a way I can always ensure that the current date and time are always entered into the datetime field?

View Replies !
Datetime Field Changed After ALTER
To archive when a row is added, I have a column called date_added which uses the data type DATETIME.

I recently added a new column to my table "ALTER TABLE mytable ADD COLUMN mycolumn INT", and my stored dates have all been changed. In hindsight, was this to be expected?

I am using PHP to both push data into MySQL and pull data from MySQL. To prevent such future blunders, is it good practice to store dates as CHAR data type, and actively store the date using PHP?

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 !
Get Records For A DATE From DATETIME Field
I have a column with type DATETIME (2004-11-23 21:19:2) and i want to do a query to get all rows='2004-11-23'. Can anyone help me with this problem?

View Replies !
Datetime Field Format Add Slashes
I have a datetime field that currently appears like this:
mm/dd/yyyy hh:mm:ss

I need to convert the dates in this field to MySQL format:
yyyy/mm/dd hh:mm:ss

It's a matter of being able to move the 'yyyy' portion to the beginning of the data field (of course adding and removing a slash

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 !
DATETIME Field Conversion In Mysql
I know that there is a function in MYSQL to define a 'datetime' type column but when I am migrating a foxpro database to MYSQL type and when foxpro has the datetime column in the format: "08/12/1999 09:39:00", how would I convert this to mysql format while I am trying to load the data in the database(using LOAD command).

I have used str_to_date functions in the past to convert the date formats between the two databases but how do we go about the datetime format.

View Replies !
Select Julian Day From Datetime Field
I am trying to build a SELECT query that allows the user to pull a specific day from a table of data. Currently, I have a year, day, and time field, so the user can SELECT * from TABLE where year = 2006 AND day = 245.

I'm dropping these three fields in exchange for one datetime field (with the format yyyy-mm-dd hh:mm). Now when I select day(datetime) = 245 no records are found because I suspect that the days are being counted as 1 - 28, 30, and 31. Is there a simple way around this like a julian day function that is included in the SELECT statement?

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 !
What Is The NOW() Function In A MySQL DateTime Field Query?
I have a monitoring script which I am trying to better understand. One of the queries is built as follows: .....

View Replies !
During Import, The AM/PM Of Datetime Field Are Saved Incorrectly - How To Fix?
I am importing from a CSV file with date format like:
12/4/2006 12:02:13 AM
12/4/2006 1:21:04 PM
into a datetime field.
It is importing the above records as:
12/4/2006 12:02:13 AM
12/4/2006 1:21:04 AM
which obviously needs correcting.
Is there a painless way to correct this during the import process?

View Replies !
A Weekly Chart, Datetime Field Confusion
I'm trying to produce a weekly chart on my site.

The site holds 4 different genres of music, and I am aiming to produce a function to compile a top 5 chart, which will list the top 5 most played songs in the past 168 hours (7 Days) for whichever genre.

I know how the function will look, but it's the SQL query which I'm having trouble with.

Here are the SQL tables as they stand. (Only relative fields mentioned)

R2M

genre
song_id
artist
track

plays

song_id
play_id
play_date (datetime field)

So to give you an idea of what I'm after, I'm looking to call the function compile_chart($genre), send the genre variable ($genre) and then create the chart. Again, it's only the SQL query which I need help with, I can produce the remainder of the code myself.

So I'm trying to SELECT the artist and track from r2m ordering the results by how many plays they have had in the past 168 hours.

View Replies !
DateTime Field And Orderby - WRONG ORDER
I have a problem using ORDERBY on a datetime field, its returning results in the wrong order, for example its returning a current list :

- 4 hours ago
- 7 days ago
- 4 hours ago
- 4 hours ago
- 1 week ago
- 15 hours ago

As you can see, that clearly wrong. I've googled and found nothing to relavent on this issue...I even tried ORDER BY UNIX_TIMESTAMP(`updated`) and no difference.

My query, incase it matters

MySQL
SELECT DISTINCT(`thread_id`) as `id` FROM `Post` ORDER BY `updated` DESC LIMIT $from, $to

View Replies !
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?

View Replies !
Generating DAILY Min&amp;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 !
DATETIME :: Store Date In Date Field
I cant seem to get the correct date to store in my date field...? am i doing something wrong using this insert command:

$sql = "INSERT INTO registration_table (date(NOW()),name,address,...........

View Replies !
Datetime Value
I need to return a datetime value like this: yyyy-mm-dd hh:mm:ss. The question is, performance wise, would I be better off storing the datetime value in a datetime column which takes up 8 bytes, and returns the data directly, or would I be better off storing it in an INT which takes 4 bytes, and then when selecting it do: from_unixtime(columnname)
Which would be the better choice?

View Replies !
DATETIME And UTC
I am currious does anyone know if I have a DATEIME Column if I can pass it a UTC and have it work properly. (not at a place I can test it at would love to know before I am).

So pass 1124908190.99 and have it in the DB as a DATETIME.

View Replies !
Datetime Now
in Mysql Control Center I have created a column DateTime
the default value shown is 0000-00-00 00:00:00

I have try to change it by now but it doesn't work
how can you get automaticly the current time?

View Replies !
Need Help With DateTime !
I have a table i.e. Schedule and it has a datetime column i.e. Start and it has the following records.

2007-11-21 08:55:12
2007-11-20 08:55:12
2007-11-19 08:55:12
2007-11-18 08:55:12
2007-11-17 08:55:12
2007-11-16 08:55:12

If the current date time is "2007-11-19 08:55:12" how will I come to know what is the very next date that is greater than this? and what is the very previous date that is less than this datetime? Technically speaking what statement/query may I use to get this?
In this case "2007-11-20 08:55:12" will be the very next date and "2007-11-18 08:55:12" will be the previous date.

View Replies !
DateTime
How do I insert the current date and time into a DateTime column using an SQL INSERT INTO statement.

View Replies !
Timestamps To DATETIME
I have a table that has a field that is a BIGINT and it contains unix timestamps. I want to convert them to the MySQL DATETIME format.
So I created a second field of DATETIME type and I want to run an UPDATE query that will take the value out of the first field convert in to insert into the second field.
Something like:Code:

UPDATE `table` SET `new_datatime` = UNIX_TO_DATETIME(`old_unixtimestamp`);

I don't know if a function like that (UNIX_TO_DATETIME) exists in MySQL.

View Replies !
MySQL Datetime
I'm trying to set up an RSS 2.0 feed and in order for it to be vaild I need to convert a datetime column in my database to an RFC-822 date-time (Wed, 02 Oct 2002 08:00:00 EST).

I'm using the following SQL, but am returning NULL in the date_format column from the query:

SELECT article_id AS id, article_title AS title, article_deck AS deck, DATE_FORMAT( 'article_date_added', '%a, %d %b %Y %T' ) AS date_format
FROM article
WHERE article_id =24 LIMIT 0 , 30

View Replies !
Datetime :: How To Pass Value?
How to pass datetime value to insert in mysql?

i need date like this: dd/mm/yyyy, and mysql use date like yyyy/mm/dd..

In delphi 7: This is what i´m trying to do and it´s no working.

Parameters.ParamByName('dtche').value:=strtodatetime(FormatDateTime('dd/mm/yyyy',date) + ' ' + FormatDateTime('hh:mm:ss', time));

View Replies !
Datetime Not Working
I am trying to add a date that a blog post was posted. However, the date is not changing.. it is remaining as 0000-00-00 00:00:00

This is my code:

PHP Code:

 $sql = "insert into entries (id, cat_id, dateposted, subject, body) 
values
('$_POST[id]', '$_POST[cat_id]', '$_POST[dateposted]', '$_POST[subject]', '$_POST[body]')";
mysql_query($sql); 

I have a feeling it is something to do with the
$_POST[dateposted]
as there is not actually a field in my form for dateposted

View Replies !
Splitting Up DATETIME
I have 3 drop down menus that display the day (values 1-31), month (values 1-12, and year (2005-2008). I need to be able to search the database for an event on a specific date and order them by today and on. My row is called date and its column type is datetime. Is there any way I can split up the datetime so each drop down can search a portion of the date? I'm using php if that helps any.

View Replies !
Select Datetime
i am getting started with some development for work, and i need to know how to select a time that is exactly 24 hours ago.
in the history table of my database, i have a datetime object formatted like this
2005-10-23 09:23:54
about 20 or so records going in there each day, and i need to find the value of this time yesterday. i looked at the mysql docs and reference manual, but it is a bit cryptic.

View Replies !
Index Datetime
I'm trying to retrieve results within a date range and have an index on a datetime field.
The following works correctly. Using explain i can see my index in use and only 1 record returned.Code:

SELECT * from table where date = '2006-09-01 12:30:00'

Once I change the "=" it blows up. The following query uses no index and therefore references every record before returning any results.Code:

SELECT * from table where date >= '2006-09-01 12:30:00'

Using LIKE helps, but it doesn't allow me to use an end date in the range.Code:

SELECT * from table where date like '2006-09%'

View Replies !
Selecting Datetime
I'm working with a table (that I didn't create) where the month, day, year, hour, and minute are entered into separate fields. Is there a way to select all of those from the database in datetime format? I just want one piece of data I can work with.

View Replies !
Datetime 8 Bytes
How MySQL operates sometimes makes me question it. I noticed, that the datetime in MySQL is 8 bytes. But, the date datatype is 3 bytes, the time datatype is 3 bytes, and the year datatype is 1 byte...that adds upto 7 bytes, and we get exactly that in the datetime in 8 bytes.
Why? And would this every change in future release versions?

View Replies !
Strings To Datetime
If I run the query Select '2006-12-14' + ' ' + '10:24:40'; in MS SQL Server
the result 2006-12-14 10:24:40 is returned as I expect.


If I run the same query in MySQL, 2016 is returned. Why?

What I want is to update a datetime field from two char fields containing the date and time parts in the above formats.I, therefore, run Update Tablename Set z=x+' '+y; where z is a column in datetime format and x and y are in char format and contains values like the above.Again this works perfectly in SQL Server but it fails in MySQL.Why? And what can I do about it.

View Replies !
Datetime Ranges
What is the right way to ask for records with a datetime field from the last X hours (from the last 24 hours or 72 hours for example?) in a query?

View Replies !
DATETIME -&gt; 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 !
Datetime Vs Char(19)
I have a table that has a datetime field filled from a web server log file. It will always be the same format, ie "YYYY-MM-DD HH:MM:SS".

I want to make an index on just the "YYYY-MM-DD" part (ie char(10)), which doesn't seem to work on a datetime field, but if I convert it to a char(19), it does. What am I losing by converting my datetime field to char(19)?

View Replies !
DATETIME Fields
Why can i no longer update my datetime fields?

SELECT * FROM x200806 WHERE MONTH(stamp)<>'6'
# =755 records

UPDATE x200806 SET DAY(stamp)=1, MONTH(stamp)=6 WHERE MONTH(stamp)<>'6'
# syntax error (likewise if i say '1' instead of 1)

UPDATE x200806 SET DAY(stamp)='1', MONTH(stamp)='6' WHERE DAY(stamp)='30' AND MONTH(stamp)='5'
# syntax error

UPDATE x200806 SET DATE(stamp)=STR_TO_DATE('1/6/2008','%d/%m/%Y') WHERE DAY(stamp)='30' AND MONTH(stamp)='5'
# syntax error

UPDATE x200806 SET stamp=STR_TO_DATE('1/6/2008','%d/%m/%Y') WHERE DAY(stamp)='30' AND MONTH(stamp)='5'
# Duplicate entry '2008-06-01 00:00:00-928897152' for key 2
But i dont want the time part changed to Zero !!

I used to be able to say SET DAY(stamp)=1 but this doesnt work any more.

View Replies !
DATETIME - Set Default Value
I have a database table (MYSQL v5.0.67) in which I store several date fields. I have set these all to be not null and to have a default value of '0000-00-00 00:00:00' e.g.

`last_login` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',

However when I run my create database script (generated from a schema design in MYSQL Workbench) it complains as follows:

Error Code : 1067
Invalid default value for 'last_login'

I leave it as nullable with no default value and run the script to create the table which works fine. I can then use a tool like SQLyog to alter the table generated and set this to be not null with a default of 0000-00-00 00:00:00 and it is happy to alter the table. Obviously this is not ideal and it should work straight from the script.

View Replies !
Incorrect Datetime Value
i have 2 servers running MySQL 5.1.11
on both there is a database with a table, and there is a column called call_start, that has DATETIME datatype.

on first server i can do: SELECT * from calls where call_start like "2008-05%"
This would show me all entries from May 2008.

Its working on first server but on second i am getting:

Incorrect datetime value "2008-05%" at row 1

View Replies !
BigInt Value To Datetime
I'm looking to do two things:

I've got a table with the primary key as a recorded date "RecDate". It's formatted as BigInt(20) with a format of YYYYMMDDHHMM. The data within this table is automatically updated using a weather station updater "vwsql" I want to add a new column "RecordedDate" as a DateTime and update all previous rows to include the RecDate in Datetime format. I understand that I will need two extra digits appended (for seconds) before I can insert the value into the new DateTime column.

To achieve this would I use a union with another column containing 00 or is there an easier way?

Once I've done that, I also want to set up the above function to run automatically. Would I define a Stored Procedure and then call it from a TRIGGER AFTER UPDATE?

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 !

Copyright © 2005-08 www.BigResource.com, All rights reserved