Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi all I want to subtract on

Status
Not open for further replies.

feltonam

MIS
Oct 1, 2003
20
GB


Hi all

I want to subtract one day from a dttm field and then return the month and year from the calculated date in short form.
EG: If DTTM 01/2/2016 I want to end up with Jan 16. Any help welcome.

 
What have you tried? What did not work for you? Answering these questions will allow us to provide better answers for you.

That being said, using two built-in SSRS functions I was able to get the output you are looking for. My final expression in the textbox for the output value is:

Code:
=Format(CDate(Fields!YourFieldNameHere.Value), "MMM yy")

Sample Input: "12/28/2010 12:42:57 AM"
Sample Output: "Dec 10"

The CDate "ensures" the passed value is converted to a date/time format, just in case it is coming in as a string instead. The Format function takes a string parameter of how you want the formatted text to appear...

Robert "Wizard" Johnson III
U.S. Military Vets MC
CSM, CSPO, MCPD, CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
Senior Database Developer
 
That provides your formatted output but I realize I missed the requirement to subtract one day from the date. This sample expression includes that calculation as well:

Code:
=Format(DateAdd(DateInterval.Day, -1, CDate(Fields!YourFieldNameHere.Value)), "MMM yy")

One question not anwered by you is what happens on the first day of a month? Should the output return the previous month? So if given 2/1/16, do you expect Feb 16 or Jan 16? What about 1/1/16? Does that return Jan 16 or Dec 15?

Based on your initial post, the first day of each month will return the month/year for the previous month. Every other day will return the current month. If that is expected, you are good. If you want the first day of each month to also return the current month, then you don't want the DateAdd function in your expression and should use my expression posted in my first response.

Robert "Wizard" Johnson III
U.S. Military Vets MC
CSM, CSPO, MCPD, CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
Senior Database Developer
 
Hi there and thanks for replying. I should have said the date is always the 1st of the month and I want to return the month and year of the last day of the previous month.
I got it with left(DATEPART,MM,[DTTM]-1),3)) +' '+ (DATEPART,YY,[DTTM-1])
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top