SQL Query find month/year and then calculate difference from start date

Hi All,
Assume I have a table with a column Start_Date. I like to know how we can build a query to so we can find the end of the month date based on the start_ date and then calculate the difference
For example lets say we have a date 12/06/2014 and now based on this we should get the end of the month date which is 30/06/2014. Now we can get the difference which is 18 days.
Thanks

Hi Jaggy99,
According to your description, you need to get the date difference between a given date and the last day of that month, right?
In this case, please try the query below.
SELECT GETDATE() AS [CURRENTDAY], DATEADD(DAY,-1,DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) + 1, 0)) AS [LASTDAY],
DATEDIFF(DAY, GETDATE (), DATEADD(DAY,-1,DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) + 1, 0))) AS [DIFFERENCE]
Regards,
Charlie Liao
TechNet Community Support

Similar Messages

  • FM to get previous fiscal month/year and calendar month/year for a date.

    Hi All,
    I am having a requirement to extract some data based on either the previous fiscal month/year or the previous calendar month/year. There is no company code input to find the fiscal/calendar month/year.
    At selection screen, user can select either fiscal or calendar selection.
    Based on the selection, the data will be extracted.
    For the system date, we need to calculate previous fiscal month/year or previous calendar month/year and populate the calculated data back to the selection-screen.
    Can you one of you please suggest an FM to find previous fiscal month/year and previous calendar month/year.
    Thanks in Advance,
    Regards
    Gowthami

    Hi Gowthami,
    You can use following function module to calculate previous / next day or month or year.
       call function '/SAPHT/DRM_CALC_DATE'
          exporting
            date      = sy-datum
            days      =
            months    =
            sign      = '-'
            years     =
          importing
            calc_date = .
    Here, you can give '-' to sign, if you want previous day / month / year.
    Here, you can give '+' to sign, if you want next day / month / year.
    And depending upon your requirement, you can pass suitable value to days / month / year.
    e.g. To calcualte last month,
       call function '/SAPHT/DRM_CALC_DATE'
          exporting
            date      = sy-datum
            days      =
            months    = 1
            sign      = '-'
            years     =
          importing
            calc_date = wv_prev_month.
    so it will give '23-01-2008' . Then convert it in the required format as per your requirement using string function concatenate.
    Hope this help you.
    Regards,
    Anil

  • Setting date,month,year and time

    How do i change the Date /month/year and time on my printer.
    My printer is    Laser Jet Professional M1212 nf mfp

    Please to here and download the User Guide.
    http://h10025.www1.hp.com/ewfrf/wc/manualCategory?cc=us&dlc=en&lc=en&product=3965849&
    Here you will find all you information you requested. 
    Say thanks by clicking the Kudos Thumbs Up to the right in the post.
    If my post resolved your problem, please mark it as an Accepted Solution ...
    I worked for HP but now I'm retired!

  • How to derive date from given month, year and day?

    Hi all,
    I have a doubt in date function. I need to create a date from the given month, year and day. How can i do it?

    consider this example
    REPORT zconvertdate001 .
    TYPES : BEGIN OF tt_date_in,
            day(2),
            sep1,
            month(3),
            sep2,
            year(4),
            END OF tt_date_in.
    DATA : wa_date_in TYPE tt_date_in VALUE '07-Jul-2006'.
    TYPES : BEGIN OF tt_date_out,
            day(2),
            month(2),
            year(4),
            END OF tt_date_out.
    DATA : wa_date_out TYPE tt_date_out.
    TRANSLATE wa_date_in-month TO UPPER CASE.
    SELECT SINGLE mnr
    INTO wa_date_out-month
    FROM t247
    WHERE spras EQ sy-langu
    AND   ktx EQ wa_date_in-month.
    CONCATENATE wa_date_in-year wa_date_out-month wa_date_in-day
           INTO wa_date_out.
    WRITE : / ' Date in:', wa_date_in,
            / 'Date out:', wa_date_out.

  • Firefox has stopped working altogether (Windows 7). It will NOT start. I have uninstalled everything that I could find to uninstall, and then re-installed.

    Firefox has stopped working altogether (Windows 7). It will NOT start. The spinning start up graphic will spin for a moment, and quit. I have uninstalled everything that I could find to uninstall, and then re-installed, but to no avail. I have followed the currently posted suggestions with out success. Any other suggestions?

    '''[http://www.mozilla.org/en-US/firefox/all/ Download Firefox Full Installer For All languages And Systems]''' {web link}
    Save the file. Then;
    Using your file browser, open the Programs folder on your computer.
    '''Windows:''' C:\Program Files
    C:\Program Files (x86)
    '''Mac:''' Open the "Applications" folder.
    '''Linux:''' Check your user manual.
    Look for, and rename any Mozilla and Firefox folders by adding '''.old''' to them.
    Now run the full installer.

  • HT1766 I lost my IPhone 4S this morning and want to increase my cloud storage so I can back it up when it finds a signal and then remotely erase it...I'm assuming the worst that whoever finds is will not callme or want to return the phone

    I lost my IPhone 4S this morning and want to increase my cloud storage so I can back it up when it finds a signal and then remotely erase it...I'm assuming the worst that whoever finds is will not call me or want to return the phone. I went to icloud but it only govers me options to increase storage from my iPhone or a synced computer (mac or PC).

    If the phone is offline there is no way to track it or send a message to it.  You can place it in lost mode to lock it and send it a message (see http://help.apple.com/icloud/#/mmfc0f0165), but this will not take place until the phone goes back online, if it ever does.  If it does, you will get an email informing you.
    You might want to read this: http://support.apple.com/kb/HT5668.

  • Need to run a sql query in the background and display the output in HTML

    Hi Guys,
    I have a link in my iprocurement webpage, when i click this link, a query (sql query) should be run and the output should be displayed in a HTML page. Any ideas of how this can be done. Help appreciated.
    We dont have OA Framework and we r using 11.5.7.
    help needed
    thanx

    Read Metalink Note 275880.1 which has the link to developer guide and personalization guide.

  • Can i save a query in one package and then can i move it into another .....

    can i (in bw 3.5)save a query in one package and then, can i move it into another package? if yes what is the procedure? if no, why? if yes , after moving can i see that query in one package or both? plzzzzzzzz its urgent....

    Hi Neeraja,
    Yes, you can save a query in one package and then move it into another package and transport the query with new package.
    There are two ways...
    1. You can change  the package assignment from one to another with the same request and transport the objects with request assigned to the new package.
    2. You can create a new request and assign the new request to new package and transport the new request with new package assignment.
    For first one, follow below process...
    Changing the assignment:
           1.      Choose  Package in the toolbar of screen area Collected Objects in RSA1 --> Transport Connection.
    The Select Objects for Changing package dialog box appears.
           2.      Select the objects whose package assignment you want to change.
    This procedure is especially useful for changing all collected objects, or a large number of them. For this reason, all indicators are set by default. Remove the indicators for individual objects where necessary.
    Note: You can only use  Details to display the details for an individual object when this is the only object that is selected.
           3.      Choose  Copy. The Change Object Directory Entry dialog box appears.
           4.      Enter the new package.
    For second one, you need to add the query in the transport organiser and assign new request and transport package and then go for transport. But this will create two requests on the same query. So, don't go for this. First step is preferable.
    Hope this helps u...
    Regards,
    KK.

  • When I import my photos from my iPhone 4S into iPhoto the location does not appear.  I have to open the info button on the photo click "photo place" then "find on map" and then the location appears.  How to I get the location to appear automatically?

    When I import my photos from my iPhone 4S into iPhoto the location does not appear.  I have to open the info button on the photo click "photo place" then "find on map" and then the location appears. How to I get the location to appear automatically when I import my photos from my iPhone?

    in your iPhoto preferences is look up location set to "automaticaly"?
    LN

  • How to get Quaters of the year if give month year and number of quarters

    My requirement is if i give the input month, year and number of quarters i want the previous quarters. Is there is any function module to get the quarters if we give month and year and number of quarters
    Thank you.

    Pradeep,
    Use the Fm TSTR_PERIODS_QUARTERS and pass the year into the IMPORT PARAM IT_YEARTAB-TSTR.
    U will get the begin & End dates of each quarter...
    reward if helpful,
    Karthik

  • I had a iMessage and a facetime account and was textin people and then exited out and then clicked inessage again and it said to setup my account and I did I signed in an decided what account people would find me by and then it just resets and sends sign

    I had a iMessage and a facetime account and was textin people and then exited out and then clicked inessage again and it said to setup my account and I did I signed in an decided what account people would find me by and then it just resets and sends sign

    iOS: Troubleshooting Messages
    iOS: Troubleshooting FaceTime and iMessage activation
    FaceTime, Game Center, Messages: Troubleshooting sign in issues

  • Is there a way to dial a contact by just typing its name in the keypad....as one can do in all the blackberry and android dialers...it is quite a job first to find the contact and then dial..

    Is there a way to dial a contact by just typing its name in the keypad....as one can do in all the blackberry and android dialers...it is quite a job first to find the contact and then dial..

    People - you critisize something you've no idea about! Smart dialing (also called T9) is NOT about text input for God's sake...it's about dialing a contact in a really quick and simple way just by clicking on one of 10 dial buttons (much bigger and easier to be tapped btw especially on the move) and the phone finds all the contacts matching typed combination
    For example I want to dial contact MLADD - I then tap on 6,5,2,3,3 and the phone searches for contacts matching all the combinations hidden on these numbers.
    Another example: see Apple's website containing contact line number specified in 2 ways: (800) MY-IPHONE (800-694-7466)
    Do you get my point now?
    I've used at least 6 different phones in my life so far and went through most of well known platforms including Symbian, Blackberry, Android, Windows Phone and now iOS. I'm very sure there is no better and faster way to quickly and easily dial somebody but by using a smart dial. Dialing somebody this way takes 2 seconds while dialing using tapping on contacts field, then typing a word using keyboard (assuming you click on a right button when on the move) takes a while longer and is frustrating.
    It's just a matter of a wider perspective when looking at this problem. If you would use it at least once - you would demand it as well.
    For people liking tapping everywhere to perform basic actions - let it be as it is, but why not to improve something by adding an additional option in setting and enable SmartDial?

  • Case statement to compare date and then count duration from only one date

    Hi All;
    I need to compare two dates and if date 1 > date 2 then consider date 2 and count its duration of appointments  from date 2
     case when CTE.scheduledstart  between [dbo].[DateTimeConvert] (new_dateofapplication) and 
             [dbo].[DateTimeConvert](ac.new_businessstartdate)
             then
            (CTE.scheduleddurationminutes)
     when  ( [dbo].[DateTimeConvert] (new_dateofapplication) >  [dbo].[DateTimeConvert](ac.new_businessstartdate))
            then
             [dbo].[DateTimeConvert](ac.new_businessstartdate)
            end as 'AFTERAPP',
    Any help on this is much appreciated
    I need to use case statement fro this
    Thanks
    Pradnya07

    when you say list of Appointments from Appointments table calculate duration from this date [dbo].[DateTimeConvert]
    do you mean find out duration from multiple record? or do you want
    suration for each row? also what represents this date here? Is it new_dateofapplication?
    can you show expected result for the data posted above?
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • If I delete my songs from my "Downloads" folder, have them in my "Trash" and then delete them from my "Trash", will I still be able to play the songs on my iTunes or will they be deleted on my iTunes as well?

    I want to clear some space on my Mac since it is filling up and I don't have much room left on it. I want to delete all my songs from my "Downloads" folder and then delete them from my "Trash" to free up space however, I'm worried that if I do this then iTunes will not play any of the songs I deleted.
    Will I still be able to play my songs on iTunes even if they are not in my "Downloads" or "Trash" folders?
    Thank you.

    All tracks in iTunes (if you use default settings) should be in various artist and album folders in the main media folder in the iTunes folder. You can right click a track to reveal its location in Finder.  If there's a copy there then it doesn't really matter what you do with other copies.
    I have never downloaded from iTunes but I thought it placed files directly in the correct locations, or is this some other downloads folder to which you are referring?
    Normally if you download a file from another source and add it to iTunes by dragging it there, or using the Add To menu item, it places a copy of the file in iTunes.  You can discard the original, but if you're concerned you can check which copy iTunes is actually using as above.

  • ITunes Match error: iTunes Match has encountered an error. Please choose Sign Out and then Sign In from the Store menu and try again.

    I have just subscribed to iTunes Match, and get the above error message.  I have signed out and signed in several times, and still get the same message.  Can anyone help with a solution?

    I have Just upgraded my mac from Itunes 11.0 to itunes 11.02, this issue occured within hours of the updated.
    It seems to occur about every couple of hours for me, I can still access the apple store, but music match just dies with the message: "iTunes Match has encountered an error. Please choose Sign Out and then Sign In from the Store menu and try again."
    As it takes a good ten minuites for itunes
    If this is also occuring in Itunes 11, the previous Discussions are probably not relevant.
    Itunes 11 has had significant changes applied, so it would be reasoble to assume this is not the same fault and Apple have some how broken Itunes again.
    I might try to downgrade to itunes 11.0, as it looks like music match faults are not high on apples priorities, it looks like took them almost a year to fix this fault last time it occured.

Maybe you are looking for

  • Premiere Elements 11 .iso Image für Blu Ray erstellen

    Hallo, Kann man mit Premiere Elements 11 ein iso Image für blu rays erstellen? Habe es mit dieser anleitung versucht, aber mir wirt der isoauswahlbereich nicht angezeigt (nur Ordner oder Disk) Adobe Premiere Elements – Hilfe | Freigeben auf DVD oder

  • Urgent!!Error in the front end when trying to view a report

    Hi All, I am getting this error when I am trying to view a report in the front-end. View Display Error Odbc driver returned an error (SQLExecDirectW). Error Details Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P State: HY000. Code: 10058. [NQODBC] [SQL_STAT

  • Removing corrupt messages in Apple Mail

    I have 6 identical messages in Apple Mail dating from 2006. I cannot delete them or move them. I've been told it is due to the messages being corrupted. OK. How do I get rid of them?

  • Does appleTV support HD 1080p ?

    hello is 1080p supported by the AppleTv? thx

  • Cannon Resolve Symbol, DiveLog Tute Example...

    I have followed the Tute "DiveLog" and cannot get it to compile... I have created the other .Java required and placed the in the same dir... Divers.java etc... All files are in c:\java\DiveLog\ FILES ARE HERE. I have set the path ver.. can complir "H