473,670 Members | 2,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Syntax for Last day of last Quarter

6 New Member
Hi,
I have a need to create a syntax , so that basing on the current_date, the sql generated will always give me the Last day of the Last Quarter.
I am new to SQL, so need help
thanks.
Ed
Nov 29 '12 #1
9 14500
Rabbit
12,516 Recognized Expert Moderator MVP
Define quarter. Calendar quarter? Fiscal Quarter? If fiscal, what is the start and end? It varies.

But the basic algorithm is this:
Expand|Select|Wrap|Line Numbers
  1. if (month of some date) <= (month of last date in fiscal year) then
  2.    use current year
  3. else
  4.    use next year
  5. end if
Nov 29 '12 #2
americanmc
6 New Member
We need the calendar quarter. So if I run the SQL now, it should give me sep 30 2012. and if I run it in Jan 2013, then it should give me 31 Dec 2012.
Nov 29 '12 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Use the date_trunc() function to get the first day of the quarter and then subtract one day.
Nov 29 '12 #4
americanmc
6 New Member
the date_trunc() function does not work in Postgres. Can u send me the correct SQL for last day of Quarter.
Nov 29 '12 #5
Rabbit
12,516 Recognized Expert Moderator MVP
Sure it does. Here is PostgreSQL's list of date/time functions. You will see that date_trunc is on there.
http://www.postgresql.org/docs/8.3/s...-datetime.html
Nov 29 '12 #6
americanmc
6 New Member
yes, it does, i apprecaite. I am getting first day of curretn quarter, still looking for how to minus one day:
select date_trunc('qua rter',current_d ate)
Nov 29 '12 #7
americanmc
6 New Member
Once again I apprecaite the help this forum is providing.
Nov 29 '12 #8
Rabbit
12,516 Recognized Expert Moderator MVP
In that same link, it also shows you how to subtract a time interval.
Nov 29 '12 #9
americanmc
6 New Member
Yes, Thanks Rabbit, it works..

select date(date_trunc ('quarter',curr ent_date))-integer '1'
Nov 30 '12 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3669
by: Neeper | last post by:
Hi, I've got a transactions table with a tstamp field (datetime type) and I need help creating a SELECT query to retrieve only last transactions that occured within the last 5 minutes. The datetime type writes the tstamp as YYYY-MM-DD HH-MM-SS and I am using mySQL 4.1. Please help.
3
14513
by: Matt | last post by:
Hello, I have a query that I would like to schedule in DTS. The criteria of this query checks for records in the table that are within the current quarter. Here is what I have. WHERE submit_date BETWEEN '01/01/2005' AND '03/31/2005' I would like to dynamically generate the Quarter End and Quarter Beginning dates within my where clause based on the date that DTWS
3
4801
by: priscilla.jenkins | last post by:
Alright, I'm really new to SQL and VBA and all this, so I might be completely off course...but just tell me. I know C and Assembly, but that doesn't help me much here. I'm trying to create a module that creates 5 queries (that a report is based on) based on a table that the user defines. My tables are named by date (not my choice), for example: -ArchivedActions05-20-05 Everything involving that seems fine. I'm getting a syntax error...
4
1903
by: ben | last post by:
getting a bit confused with the details of how c's grammar is specified, especially when you get self-reference like in this: postfix-expression: primary-expression postfix-expression postfix-expression ( argument-expression-listopt ) postfix-expression . identifier postfix-expression -> identifier postfix-expression ++
1
2914
by: Hemanth | last post by:
Hello, How do I find the first and last non-numeric char positions (using regexp) in an alphanumeric string? For example, 99ABC1A => should return 2, 6 DE8A1 => should return 0, 3 Thanks,
2
15279
by: schapopa | last post by:
Hi, I want to create query where I could group records by quarters, and get the last record in each group. e.g Create Table MyTable ( Value , date )
23
18061
by: Florian Lindner | last post by:
Hello, can I determine somehow if the iteration on a list of values is the last iteration? Example: for i in : if last_iteration: print i*i else:
2
7653
benchpolo
by: benchpolo | last post by:
First Day of the QUARTER select DATEADD(qq, DATEDIFF(qq,0,getdate()), 0) Question: How do I get the last DAY of the QUARTER? For example: 1st Quarter is 01/01/2008 to 03/31/2008. I am having difficulties finding the last day of the quarter.
4
11947
by: gimme_this_gimme_that | last post by:
Is there a way to get the last day of the previous business quarter from DB2? For 10/21/2008 the day would be 9/30/2008. Thanks.
2
2680
by: grinder332518 | last post by:
Hi I am running a “last” command and saving the output to a file, which I am going to ftp to my PC for loading into a DB table. last > last.txt I am finding that I am getting lots of duplicate entries for most logins in last.txt. Eg
0
8815
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8592
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8661
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7421
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6216
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4393
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2802
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1795
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.