Always Return the Previous Saturday's Date Using NOW Function in MS Excel 2007 - excel-2007

I have a workbook that I am using the NOW function to return today's date and then I have another cell to convert to WEEKNUM that I use to MATCH on with a different tab. I need to be able to create a formula to read today's date and always return the previous Saturday. Example: Today is 6-8-2015. I want this formula to return 6-6-2015. Any ideas on how to make this work. I am struggling here.

How about:
=NOW()-(WEEKDAY(NOW(),1))
This will return the time 'now' minus the number of days from Saturday where Sunday = 1, Monday = 2 etc.
Note, this does include the timestamp along with the day (eg. 6/6/2015 14:48). If you want just the date you could daisy-chain a text function around it.

Related

Finding the week number from a date in Visual Basic

I want to compare 2 dates and check that they are in the same week. Is there a way to find the week number of each date and compare them, or an alternative function to compare the dates and see if they're in the same week?
Thank you :)))))))))))))))))
Look at the vba Format function - use something like Format(DateVariable, "ww") to get week number of a date.
in VBA, use DateDiff which returns 0 (zero) for a match:
WeekMatch = Not CBool(DateDiff("ww", Date1, Date2, vbUseSystemDayOfWeek, vbUseSystem))

Power pivot specific day issue

I have two columns called
1ST column Calendar Date:
16/02/2015
2nd Column Previous Day:
Yes
Formula I am currently using:
if([calendar Date])=today-1,"YES","NO").
The 2nd column returns value based on the 1st column.
However , the problem I am getting is when I run the data on monday when we have calendar date (day on friday). So it is showing "NO" as formula only returns data for previous day.
So I want something like this
Only when I run on Monday it should give me if([calendar Date])=today-3,"YES","NO").And all other workdays if([calendar Date])=today-1,"YES","NO")
Can you please help me on this.
If you cell A2 has the calender date then try with below formula.
=IF(WEEKDAY(A2)=6,(IF(A2=TODAY()-3,"YES","NO")),(IF(A2=TODAY()-1,"YES","NO")))
=IF(WEEKDAY(TODAY())=2,IF(TODAY()-3 = A12, "YES", "NO"), IF(TODAY()-1 = A12, "YES", "NO"))
first, identify whether the date today is monday or the other day of the week.
IF(WEEKDAY(TODAY())=2
If today is monday, then you can create the condition that the previous day must be friday [today()-3].
IF(TODAY()-3 = A12, "YES", "NO")
If today is not monday, then create the condition that the previous day is the date yesterday [today()-1].
IF(TODAY()-1 = A12, "YES", "NO")
To disregard weekends and holidays, you will want either the NETWORKDAYS or
NETWORKDAYS.INTL¹ function. Not only can you skip a conventional Sat/Sun weekend but you can add a reference to a list of holidays to be discounted as well. The newer NETWORKDAYS.INTL has a large selection of built-in non-standard 'weekend' formats or you can write your own. e.g. "0000011" is a standard Sat/Sun weekend and "0101000" is a Tue and Thu 'weekend'.
Both NETWORKDAYS and NETWORKDAYS.INTL count the number of days inclusively so you are looking for a value of 2, not 1.
For the following example, I've reset the computer's system date to Tue 19-Jan-2016 (the day after Martin Luther King Day, 2016).
=IF(NETWORKDAYS.INTL([#[calendar Date]], TODAY(), "0000011", Z$2:Z$11)=2, "Yes", "No")
If you wanted to get a little more elaborate, just use the NETWORKDAYS.INTL function with a custom number format of [=2]\Y\e\s;\No;\No. This allows you to retain the actual underlying value of the NETWORKDAYS.INTL formula while displaying Yes or No.
    
The results from the image above clearly show that both the weekend and holiday were discarded from consideration and that Fri 15-Jan-2016 is considered the previous day.
¹ The NETWORKDAYS.INTL function was introduced with Excel 2013. It is not available in earlier versions.

How to get month within a range vb2010

I just don't know how to go about this.
I designed a program that uses MS Access as its database. I have a field for month and year (the field data type is text) where user can register details. The program will register the month and year the user have chosen e.g month= September, year=2011.
My problem now is how to chose a range of data to view by the user using the month and year as a criteria e.g the User may want to view data range from (September 2011 to July 2013).
I couldn't figure out even how to try. Help will be highly appreciated.
Perhaps you could change your application logic to store the month and year as their respective numbers rather than text and change the field data types to numeric.
You could then construct a DateTime object from them, for example September would be 9 and you could use code like the following:
var startDate = new DateTime(year, month, 1); // get year and month as integers from database, uses the first as the date
var endDate = new DateTime(year, month, 10); // change the date but keeps the month and year the same
var endDate2 = startDate.AddMonths(1); // adds 1 month to the date
Alternatively, you could try using a calendar control to allow the user to select two dates instead of building it from a number of fields. Depending on what you are using this could be achieved a number of ways, for example in ASP.Net or WPF you could use two calendar controls and just use their SelectedDate properties as your range.
A range is from a startpoint until an end point. For the startpoint you can add automatically the first of Month. For the endpoint is it more complicated because there is no fix endpoint. What you can do is following:
Write an array that contains for each month the days (e.g. 30 or 31). Except for Febrauary there is a fix pattern.
for Febrauary use the selected year to check is the year a leap year or not. If not add 28, else add 29.
After that create the date string for your SQL:
Startdate 1.9.2011. Do for the entdate the same.
After that, I think you can use the keyword between in your SQL query.
You can assume that everything is entered on the first day of each month. I would pull the information using a query to the database.
select * from [tablename] where DateSerial([colYear], [colMonth], 1) between DateSerial([fromYear], [fromMonth], 1) and DateSerial([toYear], [toMonth], 1)
In this question are some ways to do this:
First. Filter the dates in a range assuming that you use a date like '07-12-2012'
i.e. September 2011 to July 2013
Where DateColumn > '09-01-2011' and DateColumn < '07-31-2013'
OR
Specify a Date and a Year
Where month(DateColumn)='1' and year(DateColumn)='2016'
Note:
There are many ways to do this.
You can Manipulate your statement depending on your desired output.

Filtering rows based off of relation to date column

I am trying to find a good way to filter data based off of the date column (Column I in my actualy spreadsheet). I can copy the rows and all of that to another sheet just fine, but the date thing is new to me. Basically I need to know how to filter based on three situations:
If the current date is within 3-6 months of the date in Column I;
If the current date is within 0-3 months of the date in Column I;
If the current date is past the date in Column I.
Thank you for any assistance.
Sounds like you want to use the DATEDIFF VBA function. Here is an example: http://www.techonthenet.com/excel/formulas/datediff.php.
In addition to DateDiff you can use:
Date()
Year()
Month()
Day()
Functions to determine this information.

How to group by week specifying end of week day?

I need to run a report grouped by week. This could be done by using group by week(date) but the client wants to set the day of the week that marks the end of week. So it can be Tuesday, Wednesday etc. How can I work this into a group by query?
The datetime column type is unix timestamp.
The WEEK() function takes an optional second parameter to specify the start of the week:
This function returns the week number for date. The two-argument form of WEEK() enables you to specify whether the week starts on Sunday or Monday and whether the return value should be in the range from 0 to 53 or from 1 to 53.
However, it can only be set to Sunday or Monday.
UPDATE: Further to the comments below, you may want to consider adding a new column to your table to act as a grouping field, based on WEEK(DATE_ADD(date INTERVAL x DAY)), as suggested in the comments. You may want to create triggers to automatically generate this values whenever the date field is updated, and when new rows are inserted. You would then be able to create a usable index on this new field as required.