Forums » General Discussion

Thread: Getting Current Date and working with it

This question is not answered. Helpful answers available: 2. Answered answers available: 1.


Permlink Replies: 10 - Pages: 1 - Last Post: Mar 28, 2011 4:29 PM by: Teleki Threads: [ Previous | Next ]
Teleki

Posts: 36
Registered: 3/25/11
Getting Current Date and working with it
Posted: Mar 25, 2011 9:17 AM
 
  Click to reply to this thread Reply

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!



Wetty

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
 
  Click to reply to this thread Reply

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




Teleki

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
 
  Click to reply to this thread Reply

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! :)



Teleki

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
 
  Click to reply to this thread Reply

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



Teleki

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
 
  Click to reply to this thread Reply

The statement doesn't work for TOAD syntax


Wetty

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
 
  Click to reply to this thread Reply

Shouldn't be any difference.  What version of MySQL are you using?




Teleki

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
 
  Click to reply to this thread Reply

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



Wetty

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
 
  Click to reply to this thread Reply

No - what version of MySQL are you using - the actual database.


Teleki

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
 
  Click to reply to this thread Reply

Oh! Sorry!
I belive is  Microsoft SQL Server 2005 - 9.00.4035.
Is this what you are asking for?



Wetty

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
 
  Click to reply to this thread Reply

You are in the wrong forum unfortunately. This forum is for MySQL, not SQL Server.


Teleki

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
 
  Click to reply to this thread Reply

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)

Point your RSS reader here for a feed of the latest messages in all forums