hello, i need to use DQL to select records where more then X seconds has elapsed since updated_at
my understanding is that the updated_at field is set when saving a record and uses PHP's date/time (as opposed to the databases date/time)
most date/time comparison functions dont seem to work in DQL
looking here: http://stackoverflow.com/questions/2365246/in-doctrine-orm-how-can-i-sum-seconds-to-a-timestamp-field
theres an example of working with timestamps in DQL, but their example doesn't work because the function "DATE_ADD" doesnt exist.
i need something along the lines of this:
"when record was updated more then 30 seconds ago." keep in mind that the timestamp format in the database is "Y-m-d H:i:s"
any thoughts?
Watch
GitHub Core
Show your support for Zikula! Sign up at Github account and watch the Core project!
GitHub Modules
- rgasch created topic »Using PageUtil::addVar() to load script code« 11:48 AM
- michiel responded to »password problem« 10:01 AM
- mazdev responded to »Hide "Register new account" and change template to 3 col« 07:50 AM
- mesteele101 created topic »Zikula 1.3.3 - Site Search 1.5.2 - Unable to turn off plug-ins« 07:48 AM
- mesteele101 responded to »ERR (3): E_USER_ERROR: Smarty error: [in pagesvar:pagesitem2en line XXX]…« 25. May
- mazdev responded to »Pages 2.5.0 and updating - Page not found« 25. May
- mesteele101 responded to »Zikula 1.3.3 - Selecting a category in Pages not working« 25. May
Zikula Blog
- Anatomy of Open Source Projects on Mar 07
- Continuous Review on Mar 01
- Not Invented Here on Feb 24
- How to Contribute Your Code at Github on Jan 13
- 10 Steps to Coding-Nirvana: Tips for Successful Module Writing on Nov 12
- Submitting Bug Report Tickets That Get Results on Aug 17
- Cozi Tricks #1: Syntax Highlighting on Aug 07
Login
comparing updated_at in timestamplable doctrine records.
-
- Rank: Softmore
- Registered: Sep 30, 2008
- Last visit: May 29, 2010
- Posts: 201
-
- Rank: Developer
- Registered: Jun 16, 2003
- Last visit: May 29, 2010
- Posts: 1966
can't you just do the computation in PHP and do something like
Code
->where("u.updated <= ?", $timePlus30seconds);
? -
- Rank: Softmore
- Registered: Sep 30, 2008
- Last visit: May 29, 2010
- Posts: 201
-
- Rank: Softmore
- Registered: Sep 30, 2008
- Last visit: May 29, 2010
- Posts: 201
as i thought, i cant make that comparison because of the formatting, i think id need u.updated in unix time so i can make an comparison of two numbers, otherwise im comparing two strings and just not getting the result i need.
does anyone have any ideas? -
- Rank: Team Member
- Registered: Sep 06, 2006
- Last visit: May 09, 2010
- Posts: 2446
-
- Rank: Softmore
- Registered: Sep 30, 2008
- Last visit: May 29, 2010
- Posts: 201
Will give that a try and post back my findings. I find it annoying that doctrine keeps timestamps but offers now way of eaisly working with them. I mean i could select everything and make the comparison in PHP but why should i haveto increase the overhead by doing that just to solve what should be a simple issue.
Kyle -
- Rank: Softmore
- Registered: Sep 30, 2008
- Last visit: May 29, 2010
- Posts: 201
mateo, thanks for the idea, but it didnt work either.
to see how its making the comparison i issued the following in phpMyAdmin
Code
select (
updated_at - '2011-06-14 17:05:49'
) as outofdate, updated_at, NOW( ) as now, uid
from `z_zim_users`
where 1
limit 0 , 30
Code
outofdate updated_at now uid
20110614198309 2011-06-14 20:03:20 2011-06-14 17:11:25 2
we see the result above for 'outofdate' i need that to be in seconds essentially. the timestamp used in the SQL code above was generated using
my complete statment is
Code
i can't believe its this hard to make a DQL comparison of the updated timestamp to current timestamp.
there has to be an easier way that actually works
Edited by kylegio on Jun 14, 2011 - 06:32 PM. -
- Rank: Softmore
- Registered: Sep 30, 2008
- Last visit: May 29, 2010
- Posts: 201
ive discovered why the values were wrong in the database (off by 3 hours), there was some obscure piece of code somewhere in the module that was setting that value (incorrectly) and then saving it
Seems to be working going back to the original
and having my own bad fixed
Thanks for the help, and sorry to waste anyones time with a stupid mistake i made somewhere
Edited by kylegio on Jun 14, 2011 - 06:44 PM.
- Moderated by:
- Support
Users on-line
- 0 users
This list is based on users active over the last 60 minutes.
