View Single Post

   
  #4 (permalink)  
Old 02-28-2008, 10:43 AM
J.O. Aho
 
Posts: n/a
Default Re: SQL statement to select from a drupal webform table

skinhat wrote:
>> SELECT
>> DISTINCT `sid`
>> WHERE LEFT(FROM_UNIXTIME(`cid`),10) = '2007-12-08';

>
> This wouldnt work because the 'cid' field doesnt hold the date. Its
> just a unique identifier.
>


Yes, the cid column does hold the date, it's just in a unixtime format and the
FROM_UNIXTIME() function would then convert it to a human readable format

see the mysql documentation:
http://dev.mysql.com/doc/refman/5.0/..._from-unixtime

FROM_UNIXTIME(unix_timestamp), FROM_UNIXTIME(unix_timestamp,format)

Returns a representation of the unix_timestamp argument as a value in
'YYYY-MM-DD HH:MM:SS' or YYYYMMDDHHMMSS format, depending on whether the
function is used in a string or numeric context. The value is expressed in
the current time zone. unix_timestamp is an internal timestamp value such as
is produced by the UNIX_TIMESTAMP() function.

And then using the ten most left characters in the string would give you just
the YYYY-MM-DD

+------------------------------------+
| LEFT(FROM_UNIXTIME(1176015743),10) |
+------------------------------------+
| 2007-04-08 |
+------------------------------------+


--

//Aho
Reply With Quote