?
Solved

Display the last month end date in Sybase

Posted on 2006-05-10
2
Medium Priority
?
1,618 Views
Last Modified: 2007-12-19
hi,

I want to take the system date and to display in this manner .
Eg.
Last month = May 2006 – 1 month = Apr 2006
StartDate = Apr 1 2006 (first day of the month) to display as ( 1-Apr-06)
EndDate = Apr 30, 2006 (last day of the month) to display as (30-Apr-06)

thx



0
Comment
Question by:IBTLehman
2 Comments
 
LVL 2

Expert Comment

by:TadHawkins
ID: 16652053
declare @Now datetime
select  @Now = getdate()

select substring (convert (char(11), dateadd (month, -1, @Now), 106), 4, 8) 'Last Month'
      ,           convert (char(11), dateadd (month, -1, dateadd (day, 1 - datepart (day, @Now), @Now)), 106) 'Start Date'
      ,           convert (char(11), dateadd (day  , -1, dateadd (day, 1 - datepart (day, @Now), @Now)), 106) 'End Date'
0
 
LVL 6

Accepted Solution

by:
ChrisKing earned 900 total points
ID: 16658112
if you literally want those formats, then:

declare @Now datetime
select  @Now = getdate()

select substring (convert (char(11), dateadd (month, -1, @Now), 106), 4, 8) 'Last Month'
      ,           stuff(stuff(convert (char(11), dateadd (month, -1, dateadd (day, 1 - datepart (day, @Now), @Now)), 6),3,1,'-'),7,1,'-') 'StartDate'
      ,           stuff(stuff(convert (char(11), dateadd (day  , -1, dateadd (day, 1 - datepart (day, @Now), @Now)), 6),3,1,'-'),7,1,'-') 'EndDate'

 Last Month StartDate   EndDate
 ---------- ----------- -----------
 Apr 2006   01-Apr-06   30-Apr-06


(this version use 2 digit years on the dates and hyphens for seperators)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
In the below post we have mentioned the best hosting type for startups. Also, check out some of the superlative web hosting companies that are proposing affordable web hosting solutions to host your startup website.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question