start and end date of given date

Hi All,

What's the easiest way to get the start and end date for a given date. 
The Mon thru Sun dates.

4/30/2010 4:51:01 PM
sqlserver.programming 1873 articles. 0 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 18

You can use known Monday and Sunday dates and calculate based on current date (or any parameter date):

-- '20010101' is known Monday
-- '20010107' is known Sunday

DATEADD(DAY, (DATEDIFF(DAY, '20010101', CURRENT_TIMESTAMP) / 7) * 7, '20010101') AS monday_for_date,
DATEADD(DAY, (DATEDIFF(DAY, '20010101', CURRENT_TIMESTAMP) / 7) * 7, '20010107') AS sunday_for_date;

Plamen Ratchev
4/30/2010 5:27:05 PM
Thanks for the help Plamen,

"Plamen Ratchev" wrote:

> You can use known Monday and Sunday dates and calculate based on current date (or any parameter date):
> -- '20010101' is known Monday
> -- '20010107' is known Sunday
> DATEADD(DAY, (DATEDIFF(DAY, '20010101', CURRENT_TIMESTAMP) / 7) * 7, '20010101') AS monday_for_date,
> DATEADD(DAY, (DATEDIFF(DAY, '20010101', CURRENT_TIMESTAMP) / 7) * 7, '20010107') AS sunday_for_date;
> -- 
> Plamen Ratchev
> .
4/30/2010 6:25:01 PM

Similar Artilces:

Sum at end of column question
I have a delimted text file that I need to import into excel sort it by product number and total sales by product. I have to do this twice a month so I made a marco that imports the file and then using filter it filters by product number and copies the resuts to another sheet in the workbook. The trouble Im having is that I don't know how to add the entire column for total sales automatically. the total sales will always be in column C but the row number will always be different. I have tried highlighting the C column and clicking on the sum icon in the toolbar but it doesn't g...

Can't get dates to format corrrectly.
Hi, I ran a MS-Access query to pull in some data from our database and one of the date fields has the data formatted as either MM/DD/YYYY or YYYY-MM-DD. I want to change the data on the Excel sheet so that all rows display this date as MM/DD/YYYY. I tried to obvious of selecting the entire column and setting the format to just that date format but still those dates remain formatted as YYYY-MM-DD. When the data came into Excel it was set to a general format for that particular column. Any ideas on how I can accomplish this? You might try this: go to any blank cell off to the side an...

Dating using workdays
Is there a way to autofill dates into a spreadsheet and only use workdays and not Saturdays and Sundays? no Depending on version yes, put the first date in a cell, right click the cell and copy it down, when you release the mouse button you can select weekdays.. -- Regards, Peo Sjoblom "Bill" <> wrote in message news:012a01c3d543$6c197a40$a301280a@phx.gbl... > no You could try this. Put a non weekend-date in A1 Put this formula in A2 =IF(WEEKDAY(A1)=6,A1+3,A1+1) Copy it down -- HTH Bob Phillips ... looking out across Poo...

Excel Bi-weekly time sheet change dates to Thursday- Wednesday?
I downloaded a Bi-weekly timesheet for Excel. The timesheet is perfect except for the date part. The time sheet comes with a Monday to Friday bi-weekly time set-up and I need to change it to a Thursday to Wednesday bi-weekly time set-up. At present I had to individually change the days starting with the Thursday and when I change the start date and ending dates the only days that automatically change are the first Thursday to Sunday settings (4 days). How do I set it up so that all days change when I put the start date and end date at the top of the sheet? Hi Starting with the cel...

Update back-end tables, fields, relationships etc...
I am looking for some examples of code or links to code examples to update a back-end database appropriately so it works with the next version of the front-end. Both dbs are Access2007, Example: I have a table tblPreference in the back-end that has a versionNumber field and is set to "1.0". If my latest "2.0" front-end is opened I want it to detect the OLD version 1.0 back-end and run the code to update the back-end to "2.0" and then change the version number. Things I need done include: - adding fields to existing tables - deleting fields from ...

Input a date using a Form Button.
Hi, Please help as I'm totally lost with this one! I'm doing a little project for work and I have come across a littl problem with a date input that I have set up using a Form Button. No this button once pressed enters the date just as I want, into th correct Cell (the buttons called "Todays Date") Now I have recorded macro so that the button executes the =TODAY() comand - which is fin untill the date changes!! As you can emagine I need the date to stay a it was when first pressed as its a database I'm trying to compile. Does this make any sense to you all?? I will...

Generate Payment Due Date to exclude Weekends and Public Holiday
I have a table with Column A = Invoice Date Column B = Days of Credit Granted Column C = Payment Due Date Column E = List of Public Holiday with the first row as header and subsesquent rows as the actual data what i want to do is to auto generate the payment due date of each invoices so that it won't falls on weekends and public holiday. for example, if [Invoice Date] + [Days of Credit Granted] falls on a saturday, then the due date will be push forward 2 days to monday. i came out with a formula which works pretty fine given that there's no consecutive non-working days ...

Date Function
I have two different users, who have the same machines and the same version of office. However when one of the users types in a date; i.e - 10/02/2005, and then goes to format the cell, they can click on a date type that will look like; "*Thursday 10 February 2005". However on the second users machine this function is not present, all they have the option of is; "*10 February 2005". I dont know why it is missing of the day?? Can someone please help me? -- andyb7901 ------------------------------------------------------------------------ andyb7901's Profile: http:/...

macro to find date format in a cell and delete that entire row
macro to find date format in a cell and delete that entire row i have dates in a column and date keeps changing, i want that if macro find date in a column , it deletes that entire row help me thank u so much everyone for ue hel -- Message posted from try Sub deletedate() For Each c In Selection If IsDate(c) Then c.EntireRow.Delete Next End Sub -- Don Guillett SalesAid Software "vikram >" <<> wrote in message > macro to find date format in a ...

Starting a dialog box minimized
I would like my dialog-based application to start up with the dialog box minimized. One of the properties of the main window in a window-based application is to start minimized but that property isn't present for the dialog box. I've looked through the various messages but the only ones I see are ones that are sent to the window when it gets minimized - none to tell it to minimize. Ive tried placing "PostMessage(WM_SIZE, SIZE_MINIMIZED, 0);" in my "xxx::OnInitDialog()" function but that doesn't do it. How should this be done? Thanks, Ray Mitchell ...

Email router doesn't start (Microsoft.Crm.Tools.EmailAgent.SystemS
Hi I get this message in the event log when trying to restart the mscrm email router service. This was working until a day ago but not anymore. I have looked at the actual file and there is nothing in it like no data - 0KB. I have repaired email router but no luck.. any ideas what else i could pelase try. Regards Snow White Have you tried to restart the "Microsoft CRM Email Router" service on server? are you not able to access email router configuration ? Btw are we talking about CRM 4.0? /Aamir Hi Aamir this is crm 4.0 Yes i have tried to restart the service and the error...

How can i change cell colour depending on month of date in cell?
I have a column with a range of dates corresponding to when an item was tested and would like to automatically change the colour depending o which month it was tested. Jan-Mar = red, Apr-Jun= green, Jul-Sep blue and Oct-Dec= yellow. No date = no colour. Anyone have an suggestions? Do I need to run a macro or is there a simpler way? Thanks And -- andy7 ----------------------------------------------------------------------- andy75's Profile: View this thread: ...

COUNTIF function with date range
Is there anyway to use the COUNTIF function with a date range. I'm trying to count each date within a particular month. For example, =COUNTIF(G5:G100, "12/**/03" And this example with the wildcards is currently not working. Thanks. Amy Hi, Try, =SUMPRODUCT(--(MONTH(G5:G100)=12)) Hope this helps! In article <fd8501c43e96$22a9daf0$a401280a@phx.gbl>, "Amy" <> wrote: > Is there anyway to use the COUNTIF function with a date > range. I'm trying to count each date within a particular > month. For ...

Inbox Date Stamp Is Wrong
In Outlook 2003, the date on received emails is already showing the year 2004. My system date is set correctly. I have sent and had others send me emails through both of my accounts and the date still comes through as 2004. Should I create a new profile? Is there a place to modify this somewhere in Outlook or in the registry? Thanks for your ideas. Dave hmmm. if your clock is right and the senders clock is right then .. is it an ISP problem ? is it the 'sent' or 'received' time which is wrong ? are they the same ? are they logical ? N "Dave T." <anony...

visio current date and time fields
How can i search a shape's text for occurrences of current date and time fields. Is there a way I can just search the text for a time field and a date field of any format? Thanks in advance. Hello Biggaford, The text of the shape will only return a mix of the inserted field and so you would be able to check for the the 'current date/time' as opposed to just an abitary date using Edit / Find. If you know the format that was used for the inserted fields you might be able to search using a pattern such as: ^?^?/^?^?/^?^?^?^? ....which will return a match for a date. Other...

How to get formulas starting from the referenced cells
Hi all, I've cells on a sheet which are referenced by formulas which are on different sheets (about 20) on the same workbook, and I'm looking for a way to get all these formulas. I've tried: 1) The Trace command, but I see only a table icon every time I've this type of reference 2) The Find command, but there are cell references wrote in different manners (ie B2, $B2, B$2, $B$2), and formulas which refer to results of other formulas that refer to the cells, so it's not so simple to trace all the dependencies Any help is appreciated Thanks Dario I'm not sure I full...

Show only Journal entries in Delete bin, sort by deletion date
I posted a number of times about the problems I encountered with Ctrl- D (delete a Journal item) being right beside Ctrl-S (saving a journal item). On occasions where I actually notice an accidental deletion, one thing that could help is to be able to view only journal items in the Delete bin. Is there a way to do this? Another thing that might help is to be able to sort by deletion date. Is there a way to do this? Sometimes, I accidentally delete a journal entry from way back, and that basically means its buried in the Delete bin (which is normally sorted by date). Even if the d...

Printing Dates on One Sheet
I have one template that i print for our production floor. Each sheet has seven dates printed; Monday thru Sunday. I need to print this one template 52 times for each week of the year. Is there a formula that i could enter one day (i.e. the first date for the first monday) and automtically print the rest of the weeks. in essence, press the print button one time, but the same template will print 52 times with each week on the sheet? So you have 7 rows on each sheet and 52 sheets? If I were you, I'd collate everything on one summary sheet and filter your data there. Check...

auto start up and turn off
i'm researching about installation or configuration.. we are developing a pos program. our client wants to run the program when he turns the computer, and when he close that program computer must be turned off... i heard that when we install windows with script file, we could make that happen. anybody know any articles or instruction about this? Jake you can add the POS executable (exe file) in the startup directory for all users - this will launch the POS program when computer is turned on -- I don't know if you can get windows to shut down when an executable is terminated - ma...

Transaction versus Post Dates
I'm a long time customer of Microsoft Money and I have recently ran into a problem that I believe would be solved with offering the ability to track transaction and account posting dates separately. Right now with Microsoft Money (I'm using version 2005), one must choose if he/she wishes to use the date as the time of the actual transaction or the date it posted to the account. Naturally using the posting date would be advantageous when sync'ing with your bank and performing balances. However, this gets me into a problem with taxes. I track sales tax of EVERY transaction...

Files opening at start-up
I just got a new computer and was setting up defaults in Excel, and I mistakenly entered 'My Documents' in the Tools/Options/General field for "At startup, open all files in." So when I start Excel it tries to open EVERY file in My Domuments and I have to use Task Manager to kill it. I opened in Safe Mode to change that option, but that doesn't seem to work. (Ie, when I open Excel again in regular mode it goes back to opening every file.) Is there another way to fix this? THanks! Andrew Can you use Windows Explorer to rename that "my Documents" folder, then ...

Date Difference Calculation Between two Records
If somebody can help me , regarding calculating difference of days between to records. Ex: Record No: Date: Receipts Payments 123 01/04/2007 10000 456 10/04/2007 5000 789 20/05/2007 500 What i need is calculate date difference in two records Record No: Diff 456 9 Days 789 40 Days I need this days for interest calculation if somebody could please suggest how to calculate this date difference in query i will be very much grateful ...

Money 2005 start-up error 12-13-09
After the most recent update, I am now getting an error message from 2005 standard, that it encountered an internal error and has to close. There no re-store function to previous install/update. Any idea what to do? I am receiving the same exact problem on two different PC's here. One PC has Vista and one has XP, so I am assuming this is a Microsoft problem and not one of either of the individual PC's I'm working on. Any guidance would be extremely helpful. "squirrel" wrote: > After the most recent update, I am now getting an error message from 2005...

Some Cells display text others dates in the same column
I imported a .csv file into Excel. One column contains the SKU # of a product. All my SKU's are formatted as x-xxxx. However some of the cells in the column display the SKU as it should, but many (45 out of 170) are displayed as a date format mmm-yy. Each one of the 45 is different. The cells in question show up as "custom" and when I try to change it to "text" I get a completey different number than the SKU I need. Somebody please help. Hi Phil, Format the entire column manually, choose Format, Cells, Number tab, Custom and enter #-#### in the Type box...

Extracting Dates
I have a column of random dates ranging from 1-1-2007 to 1-1-2017 in the format of ddmmmyy. I am trying to create two more columns of data, one containing the year, and one containing the month. Is it possible to use a formula to extract these without having to sort individually and input manually. Assume that your Date is in A1 cell Copy and paste the below formula in B1 cell for getting the Month. =MONTH(A1) Or =TEXT(A1,"MMM") Copy and paste the below formula in C1 cell for getting the Year. =YEAR(A1) Remember to Click Yes, if this post helps! ------...