|
Replies:
10
-
Pages:
1
-
Last Post:
Mar 28, 2011 4:29 PM
by: Teleki
|
|
|
Posts:
36
Registered:
3/25/11
|
|
|
|
Getting Current Date and working with it
Posted:
Mar 25, 2011 9:17 AM
|
|
|
Hi! I am working on a query I need to run monthly. This query includes a "date" field which I need to fill in with the LAST day of the PREVIOUS month of this year. I am trying to do this by: SELECT ([31/] + MONTH(DATEADD(mm,-1,DATE())) + '[/]' + YEAR(DATE())) as MyTime
But it tells me that "there are too few parameters". Also, this is not a very good solution since not every month has 31 days. I would very much appreciate any ideas you cane give me. And thanks in advance for you time!
|
|
|
Posts:
4
Registered:
3/25/11
|
|
|
|
Re: Getting Current Date and working with it
Posted:
Mar 25, 2011 1:36 PM
in response to: Teleki
|
|
|
If I understand your question correctly - you want the last day of the previous month? MySQL has a LAST_DAY function already.
SELECT DATE_SUB(LAST_DAY(now()), INTERVAL 1 MONTH)
Hope that helps
|
|
|
Posts:
36
Registered:
3/25/11
|
|
|
|
Re: Getting Current Date and working with it
Posted:
Mar 28, 2011 12:04 PM
in response to: Teleki
|
|
|
Thank you very much!! I think that's exactly what I need. I'll try the trick today and let you know. Maybe it was a very dumb question, but I'm a newby so... sorry for wasting your time! :)
|
|
|
Posts:
36
Registered:
3/25/11
|
|
|
|
Re: Getting Current Date and working with it
Posted:
Mar 28, 2011 12:15 PM
in response to: Wetty
|
|
|
Hi Wetty, So I tried the statement just as you posted it but it gives me an error saying the there is a syntax error(missing operator) in query expression. Is the syntax for MySQL the same as for TOAD for Data Analyst? Thank you
|
|
|
Posts:
36
Registered:
3/25/11
|
|
|
|
Re: Getting Current Date and working with it
Posted:
Mar 28, 2011 12:16 PM
in response to: Teleki
|
|
|
The statement doesn't work for TOAD syntax
|
|
|
Posts:
4
Registered:
3/25/11
|
|
|
|
Re: Getting Current Date and working with it
Posted:
Mar 28, 2011 3:51 PM
in response to: Teleki
|
|
|
Shouldn't be any difference. What version of MySQL are you using?
|
|
|
Posts:
36
Registered:
3/25/11
|
|
|
|
Re: Getting Current Date and working with it
Posted:
Mar 28, 2011 4:07 PM
in response to: Wetty
|
|
|
I'm using TOAD for Data Analyst 2.6.2.580. I realised that some of the statements in SQL are different, although not really sure why! :S
|
|
|
Posts:
4
Registered:
3/25/11
|
|
|
|
Re: Getting Current Date and working with it
Posted:
Mar 28, 2011 4:11 PM
in response to: Teleki
|
|
|
No - what version of MySQL are you using - the actual database.
|
|
|
Posts:
36
Registered:
3/25/11
|
|
|
|
Re: Getting Current Date and working with it
Posted:
Mar 28, 2011 4:16 PM
in response to: Wetty
|
|
|
Oh! Sorry! I belive is Microsoft SQL Server 2005 - 9.00.4035. Is this what you are asking for?
|
|
|
Posts:
4
Registered:
3/25/11
|
|
|
|
Re: Getting Current Date and working with it
Posted:
Mar 28, 2011 4:21 PM
in response to: Teleki
|
|
|
You are in the wrong forum unfortunately. This forum is for MySQL, not SQL Server.
|
|
|
Posts:
36
Registered:
3/25/11
|
|
|
|
Re: Getting Current Date and working with it
Posted:
Mar 28, 2011 4:29 PM
in response to: Wetty
|
|
|
You are right. Sorry about that and thanks for your time! :)
|
|
|
|
Legend
|
|
Guru: 2001
+
pts
|
|
Expert: 751
- 2000
pts
|
|
Enthusiast: 31
- 750
pts
|
|
Novice: 0
- 30
pts
|
|
Moderators
|
|
Helpful answer
(5 pts)
|
|
Answered
(10 pts)
|
|