Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Get the time value from NOW();
Old 04-12-2010, 12:23 PM Get the time value from NOW();
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
How can i show rows after a certain time.

I have a var named loggedinat that holds a value like "2010-03-09 21:17:30"

I then want to select all rows from a table that have a timestamp newer than the above time..

( Ie, it shows newer rows than the time above )

SELECT * from test WHERE when >= '$logginat' ORDER BY id ASC limit 100;

Ima ssuming i need to do something else here to try and get mysql to understand the two values correctly?

Any ideas guys?

Thanks
G
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
 
Register now for full access!
Old 04-12-2010, 01:05 PM Re: Get the time value from NOW();
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Your query should work.
I just quickly tested it against a datetime field and a varchar field, and mysql does the casting from varchar to datetime automatically.

Code:
mysql> create table dtmTest( dtmReal datetime, strVal varchar(100));
Query OK, 0 rows affected (0.07 sec)

mysql> insert into dtmTest values ('2010-03-09 21:17:30','2010-03-09 21:17:30');
Query OK, 1 row affected (0.04 sec)

mysql> select * from dtmTest;
+---------------------+---------------------+
| dtmReal             | strVal              |
+---------------------+---------------------+
| 2010-03-09 21:17:30 | 2010-03-09 21:17:30 |
+---------------------+---------------------+
1 row in set (0.00 sec)

mysql> select 'found' from dtmTest where dtmReal < '2010-03-09 22:17:30';
+-------+
| found |
+-------+
| found |
+-------+
1 row in set (0.00 sec)

mysql> select 'found' from dtmTest where strVal < '2010-03-09 22:17:30';
+-------+
| found |
+-------+
| found |
+-------+
1 row in set (0.00 sec)

mysql> select 'found' from dtmTest where strVal < '2010-03-09 20:17:30';
Empty set (0.00 sec)
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 04-12-2010, 01:06 PM Re: Get the time value from NOW();
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
If your variable is a string you may need to convert it to a mysql dateformat.

http://dev.mysql.com/doc/refman/5.1/...on_str-to-date
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-12-2010, 01:08 PM Re: Get the time value from NOW();
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Or not as the case maybe
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-12-2010, 02:36 PM Re: Get the time value from NOW();
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Ah ha,
Thanks guys, Ive found teh issue, Looks like the "when" clause was a reserved word in sql.

( it loooks really strange when i readi t back to myself )
Ive changed the feildname and POW it works.

Thanks
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 04-12-2010, 02:40 PM Re: Get the time value from NOW();
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Hummm, saying that.

I doesnt.

it either returns all rows or none.

Not "some" that are newer than the value in my $string.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 04-12-2010, 02:53 PM Re: Get the time value from NOW();
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Humm, looks like the issue is with a previous statement not putting the data into the session..
Odd ..

Ah well.
Thansk
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Reply     « Reply to Get the time value from NOW();
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19024 seconds with 12 queries