Why doesn't this return anything ?
SELECT DATE_SUB('FROM_DAYS(TO_DAYS(2005-09-28 18:04:19))', INTERVAL 6 DAY) 7 1600 Why doesn't this return anything ?
SELECT DATE_SUB('FROM_DAYS(TO_DAYS(2005-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...
---
Steve
meltedown wrote: Why doesn't this return anything ?
SELECT DATE_SUB('FROM_DAYS(TO_DAYS(2005-09-28 18:04:19))', INTERVAL 6 DAY)
I would imagine it's because you have quotes around
FROM_DAYS(TO_DAYS(2005-09-28 18:04:19)).
--
Oli
Steve wrote: Why doesn't this return anything ?
SELECT DATE_SUB('FROM_DAYS(TO_DAYS(2005-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...
--- Steve
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_DAYS(TO_DAYS(2005-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.
>> Why doesn't this return anything ? SELECT DATE_SUB('FROM_DAYS(TO_DAYS(2005-09-28 18:04:19))', INTERVAL 6 DAY)
'FROM_DAYS(TO_DAYS(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.
You might want:
SELECT DATE_SUB(FROM_DAYS(TO_DAYS('2005-09-28 18:04:19')), INTERVAL 6 DAY)
but I'm not sure I understand what the point of the FROM_DAYS and TO_DAYS
calls is.
Gordon L. Burditt
meltedown said the following on 04/10/2005 18:40: Steve wrote:
Why doesn't this return anything ?
SELECT DATE_SUB('FROM_DAYS(TO_DAYS(2005-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...
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_DAYS(TO_DAYS(2005-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.
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_DAYS()) gets you
back where you started, assuming you had the syntax correct).
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))
--
Oli
Oli Filth wrote: meltedown said the following on 04/10/2005 18:40:
Steve wrote:
Why doesn't this return anything ?
SELECT DATE_SUB('FROM_DAYS(TO_DAYS(2005-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...
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_DAYS(TO_DAYS(2005-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.
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_DAYS()) gets you back where you started, assuming you had the syntax correct).
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. 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))
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: Oli Filth wrote:
meltedown said the following on 04/10/2005 18:40:
> Why doesn't this return anything ? > > SELECT DATE_SUB('FROM_DAYS(TO_DAYS(2005-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.
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_DAYS()) gets you back where you started, assuming you had the syntax correct).
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.
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) 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))
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.
Your original query (with the quotes where they were) could never have
worked, as 'FROM_DAYS(TO_DAYS(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.
--
Oli This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mystery Man |
last post by:
Does anyone know if Microsoft is planning to add a DATE only data type
to SQLServer.
I know that you could use a datetime and convert/cast or use datepart
to compare, but this can be tedious and...
|
by: Marc Pelletier |
last post by:
Hello,
I have a table with a Day field, defined as smalldatetime. I am filling it
from a CSharp application with the following code:
DataRow r = dtStaDays.NewRow();
r= station_ID;
r =...
|
by: David Thomas |
last post by:
Hi, I've written a simple script to test the current date and perform
an action depending on the result.
The problem is, the date displays correctly as a complete date in an
alert box but when I...
|
by: Mike Hyndman |
last post by:
I have a small script on a website that that changes the greeting
according to the time of day and displays the current day and date. This
works fine in Internet Explorer, but when viewed in Opera,...
|
by: John M |
last post by:
I want to select records which meet different criteria. I have a combo box
which takes the dates from the table containing the records. I select the
date from the menu, then open the form which...
|
by: jojoba |
last post by:
Hi,
I hope this post is ok for this group.
Here's my deal:
I have two computers on my LAN at home.
One desktop. One laptop.
Both computers are wireless enabled (and wired enabled too).
I...
|
by: maflatoun |
last post by:
Hi,
I have the following function to convert UTC time to Local time. It
works perfect for GMT- (Minus) time zones however it provides incorrect
results for GMT+(Plus) time zones?
// Format to...
|
by: peteh |
last post by:
Hi All;
We have many production jobs that "load from cursor" to a UDB/AIX 8.2
(with dpf) data warehouse from source tables residing Oracle 9i. Since
Oracle dates are (roughly) equivalent to DB2...
|
by: =?Utf-8?B?U2lzbmF6?= |
last post by:
I'm having a very strange problem I can't seem to figure out and am hoping
maybe somebody has seen it before.
I get an exception "Cast string to date is invalid" with this chunk of code:
'...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |