Uh. Dunno. What are you typing it into? What language do you think it
is? It looks a bit like a MySQL query, but mangled; is that what you
intended? If it is, why are there single quotes around the first
argument to DATE_SUB()? Is there another DATE_SUB() that expects a
string rather than a date? Yes, it's definitely a mystery...
Steve wrote:[color=blue][color=green]
>>Why doesn't this return anything ?
>>
>>SELECT DATE_SUB('FROM_ DAYS(TO_DAYS(20 05-09-28 18:04:19))', INTERVAL 6 DAY)[/color]
>
>
> Uh. Dunno. What are you typing it into? What language do you think it
> is? It looks a bit like a MySQL query, but mangled; is that what you
> intended? If it is, why are there single quotes around the first
> argument to DATE_SUB()? Is there another DATE_SUB() that expects a
> string rather than a date? Yes, it's definitely a mystery...
>
> ---
> Steve
>[/color]
Its mysql.
If I take the quotes out, I get an error
query failed:1064: You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near '18:04:19)), INTERVAL 6 DAY)' at line 1
'FROM_DAYS(TO_D AYS(2005-09-28 18:04:19))' is not a valid date.
Valid dates don't have a bunch of underscores, parentheses, and alphabetic
junk in them.
meltedown said the following on 04/10/2005 18:40:[color=blue]
> Steve wrote:
>[color=green][color=darkred]
>>> Why doesn't this return anything ?
>>>
>>> SELECT DATE_SUB('FROM_ DAYS(TO_DAYS(20 05-09-28 18:04:19))', INTERVAL 6
>>> DAY)[/color]
>>
>>
>>
>> Uh. Dunno. What are you typing it into? What language do you think it
>> is? It looks a bit like a MySQL query, but mangled; is that what you
>> intended? If it is, why are there single quotes around the first
>> argument to DATE_SUB()? Is there another DATE_SUB() that expects a
>> string rather than a date? Yes, it's definitely a mystery...
>>
>>[/color]
> Its mysql.
>
> If I take the quotes out, I get an error
>
>
> query failed:1064: You have an error in your SQL syntax; check the
> manual that corresponds to your MySQL server version for the right
> syntax to use near '18:04:19)), INTERVAL 6 DAY)' at line 1
>
> query was:
> SELECT DATE_SUB(FROM_D AYS(TO_DAYS(200 5-09-28 18:04:19)), INTERVAL 6 DAY)
>
> I'm trying to get the date that's a week before the date in the query.[/color]
If you had bothered to RTFM, you would've found that you can put the
date straight into DATE_SUB (seeing as FROM_DAYS(TO_DA YS()) gets you
back where you started, assuming you had the syntax correct).
Oli Filth wrote:[color=blue]
> meltedown said the following on 04/10/2005 18:40:
>[color=green]
>> Steve wrote:
>>[color=darkred]
>>>> Why doesn't this return anything ?
>>>>
>>>> SELECT DATE_SUB('FROM_ DAYS(TO_DAYS(20 05-09-28 18:04:19))', INTERVAL
>>>> 6 DAY)
>>>
>>>
>>>
>>>
>>> Uh. Dunno. What are you typing it into? What language do you think it
>>> is? It looks a bit like a MySQL query, but mangled; is that what you
>>> intended? If it is, why are there single quotes around the first
>>> argument to DATE_SUB()? Is there another DATE_SUB() that expects a
>>> string rather than a date? Yes, it's definitely a mystery...
>>>
>>>[/color]
>> Its mysql.
>>
>> If I take the quotes out, I get an error
>>
>>
>> query failed:1064: You have an error in your SQL syntax; check the
>> manual that corresponds to your MySQL server version for the right
>> syntax to use near '18:04:19)), INTERVAL 6 DAY)' at line 1
>>
>> query was:
>> SELECT DATE_SUB(FROM_D AYS(TO_DAYS(200 5-09-28 18:04:19)), INTERVAL 6 DAY)
>>
>> I'm trying to get the date that's a week before the date in the query.[/color]
>
>
> If you had bothered to RTFM, you would've found that you can put the
> date straight into DATE_SUB (seeing as FROM_DAYS(TO_DA YS()) gets you
> back where you started, assuming you had the syntax correct).[/color]
I've tried to read the date functions section but it is written in
neo-colonial greek. That's early greek, before Athens was even a city.
I've got all the best books, and they aren't much better.[color=blue]
>
> Note also that a week is 7 days long!
>
> SELECT DATE_SUB('2005-09-28 18:04:19', INTERVAL 7 DAY)
>
> If you don't want the time in the result, then cast it to a DATE, i.e.:
>
> SELECT DATE(DATE_SUB(' 2005-09-28 18:04:19', INTERVAL 7 DAY))
>
>[/color]
Thanks, that seems to work. The other worked for a long time, I don't
know why it would work and then not work. The only thing different was
the date.
meltedown said the following on 04/10/2005 22:50:[color=blue]
> Oli Filth wrote:
>[color=green]
>> meltedown said the following on 04/10/2005 18:40:
>>[color=darkred]
>>>>> Why doesn't this return anything ?
>>>>>
>>>>> SELECT DATE_SUB('FROM_ DAYS(TO_DAYS(20 05-09-28 18:04:19))', INTERVAL
>>>>> 6 DAY)
>>>>
>>>
>>> I'm trying to get the date that's a week before the date in the query.[/color]
>>
>>
>> If you had bothered to RTFM, you would've found that you can put the
>> date straight into DATE_SUB (seeing as FROM_DAYS(TO_DA YS()) gets you
>> back where you started, assuming you had the syntax correct).[/color]
>
>
> I've tried to read the date functions section but it is written in
> neo-colonial greek. That's early greek, before Athens was even a city.
> I've got all the best books, and they aren't much better.[/color]
I agree, the manual is somewhat dense and cryptic, but there are *lots*
of examples, including one as follows:
SELECT DATE_SUB('1998-01-02', INTERVAL 31 DAY)[color=blue]
>[color=green]
>>
>> Note also that a week is 7 days long!
>>
>> SELECT DATE_SUB('2005-09-28 18:04:19', INTERVAL 7 DAY)
>>
>> If you don't want the time in the result, then cast it to a DATE, i.e.:
>>
>> SELECT DATE(DATE_SUB(' 2005-09-28 18:04:19', INTERVAL 7 DAY))
>>
>>[/color]
> Thanks, that seems to work. The other worked for a long time, I don't
> know why it would work and then not work. The only thing different was
> the date.[/color]
Your original query (with the quotes where they were) could never have
worked, as 'FROM_DAYS(TO_D AYS(2005-09-28 18:04:19))' is not a valid date
string. ;)
All it does is truncate the invalid date string to nothing, and hence
you will get a NULL return value.
Comment