Remove weekends from a date range in PHP - calendar

I need to create a calendar showing holidays booked by staff so need to remove weekends from any date range where the booking goes across a weekend
This creates a list of dates from the start date to end date of a booking.
How do I print out just working days being requested?
$datediff = strtotime($end) - strtotime($start);
$datediff = floor($datediff/(60*60*24));
for($i = 0; $i < $datediff + 1; $i++){
$dates= date("Y-m-d", strtotime($start . ' + ' . $i . 'day'));
}

Related

formatting yyyy/mm/dd in VB Script to Month name and day date

How can you format yyyy/mm/dd in VBScript to only Output Month name and day date 'Month Name' 'Day' eg. June 6
Sorry if this is a bad question - new to VBScript. My research has found only super lengthy solutions and just numeric formatting and rearranging, I need month name!
Recent attempt (please notice I'm trying to use (DatePart("m" but I also need to output the HTML etc I am writing within <section id='
<%
today = Date
firstDay = DateValue("2015-05-10")
lastDay = DateValue("2015-06-08")
d = firstDay
While d <= lastDay
If d = today Then
response.write "today"
Else
response.write(DatePart("m","<section id='day_"& d &"' class='calSquare " & time &"'><article class='dateImage' style='background-image: url(images/Calendar_Thumbnails/Day_"&d&".jpg)'></article></article><article class='dateTitle'> "&d&suffix&"</article></section>"))
End If
d = d + 1
Wend
<!--response.write(products(0))-->
%>
The above failed; also tried MonthName but couldn't use properly maintaining the html I'm populating.. Any suggestions as to how to output MonthName and then just numeric day date, maintaining my HTML I am populating dynamically as seen in above code?
You can use the MONTHNAME function. It takes a integer not a date so you could do something like the following.
MONTHNAME(MONTH("1/12/2015")) & " " & DAY("1/12/2015")
Output:
January 12
Use d.month to get the month and do.year to get the year. Convert the d.month to month name by creating a function to do so

Selecting Slicers in VBA listed as Array since its become a Data Model?

I cannot select these powerpivot slicers with variables. They are dates (Monday-Saturday or 1/19-1/25). For some reason I cannot figure out how to select the slicers without the static dates and instead my date strings from a Monday string and Saturday string? I tried concatenating them in but no success.
Sheets("Phone Report").Select
ActiveWorkbook.SlicerCaches("Slicer_Weeks_Ago").VisibleSlicerItemsList = Array _
( _
"[Phone Cube Query].[Weeks Ago].&[01/12 - 01/17]") 'So want to replace the 01/12 and the 01/17 with my string variables?
ActiveWorkbook.SlicerCaches("Slicer_Day_and_Rank").VisibleSlicerItemsList = _
Array( _
"[Phone Cube Query].[Day and Rank].&[1. Monday]", _
"[Phone Cube Query].[Day and Rank].&[2. Tuesday]")
Variables:
Today = Weekday(Date, vbMonday)
If Today = 2 Then
Todayy = Date
Monday = Date - 1
ElseIf Today = 3 Then
Todayy = Date
Monday = Date - 2
ElseIf Today = 4 Then
Todayy = Date
Monday = Date - 3
ElseIf Today = 5 Then
Todayy = Date
Monday = Date - 4
ElseIf Today = 1 Then
Todayy = Date - 2
Monday = Date - 7
End If
Todayy=left(Todayy, 5)
Monday=left(Monday, 5)
Thanks for any possible help or suggestions.
I'm sure you found an answer by now. I had this issue for weeks and I tried to make complicated loops, but I found an easier way.
Yes, the macro recording shows an array of the slicer information. I found out if you delete the array() portion of the code you can do exactly what you need.
Here's my quick example. Operation is the variable:
ActiveWorkbook.SlicerCaches("Slicer_Oper").VisibleSlicerItemsList = Array( _"[Actuals_Table].[Oper].& [" & Operation & "]")
Changed to
ActiveWorkbook.SlicerCaches("Slicer_Oper").VisibleSlicerItemsList = "[Actuals_Table].[Oper].&[" & Operation & "]"

Magento using operators in where clauses

My products have date_created and expires_in attributes. date_created is Magento date backend format while expires_in is a select that contains options as 1 week, 1 month etc.
Using those two attributes I'm trying to determine the total number of expired products. My idea was to write a query that selects:
products where date created + 1 week < now() AND expires_in = 1 week
AND
products where date created + 1 month < now() AND expires_in = 1 month
...
But I don't seem to be able to make even the first part of the first step to work:
$currentTimestamp = Mage::getModel('core/date')->timestamp(time());
$oneWeekTimestamp = Mage::getModel('core/date')->timestamp(strtotime("+1 week"));
$products = Mage::getResourceModel('catalog/product_collection')
->setStoreId(Mage::app()->getStore()->getId())
->addAttributeToSelect('')
...
//these are what i have tried so far:
$products->addAttributeToFilter('date_updated + ' . $oneWeekTimestamp , array('gt' => $currentTimestamp));
$products->addAttributeToFilter(new Zend_Db_Expr('date_updated + ' . $oneWeekTimestamp), array('gt' => $currentTimestamp));
$products->addAttributeToFilter("DATEDIFF($currentTimestamp, 'date_updated')" , array('gt' => 7));
$countExpired = $products -> count();
None of them seem to work. If possible I'd like the cross RDBMS solution.
You can do this in following way:
$currentTimestamp = Mage::getModel('core/date')->timestamp(time());
$oneWeekTimestamp = Mage::getModel('core/date')->timestamp(strtotime("+1 week"));
$oneweekDate=date("Y-m-d H:i:s",$oneWeekTimestamp);
$products->addAttributeToFilter('date_updated',array('date'=>true,'gt',$oneweekDate);

Base SAS: Transposing Counts By Date Var

I need to create a summary dataset/report which tracks the flow of these purchases over time.I have a dataset which gives a signup date for an overall service and 9 variables which give the purchase dates for different add on products. If the add on variable dates match the signup date then those add on products were included with the signup package. Any add on variable purchase date that comes after the signup date are products which are purchased during the history of the active account. This is what it looks like:
data have ;
length ID 8
signup_DT 8 preferredhd_tv_estbd_dt 8
ultimate_estbd_dt 8 quant_estbd_dt 8
FullyLoaded_estbd_dt 8 HB_estbd_dt Cin_estbd_dt 8
time_estbd_dt 8 router_estbd_dt internet_estbd_dt 8;
INPUT ID 8
signup_DT : anydtdte9. preferredhd_tv_estbd_dt : anydtdte9.
ultimate_estbd_dt : anydtdte9. quant_estbd_dt : anydtdte9.
FullyLoaded_estbd_dt : anydtdte9. HB_estbd_dt Cin_estbd_dt : anydtdte9.
time_estbd_dt : anydtdte9. router_estbd_dt internet_estbd_dt : anydtdte9. ;;
format signup_DT preferredhd_tv_estbd_dt
ultimate_estbd_dt quant_estbd_dt
FullyLoaded_estbd_dt HB_estbd_dt Cin_estbd_dt
time_estbd_dt router_estbd_dt internet_estbd_dt date9.;
datalines;
98663699 4/7/14 4/9/14 4/7/14 9/12/14 10/15/14 7/7/14 4/7/14 4/7/14 4/12/14 .
33663798 4/11/14 . 4/11/14 . 4/11/14 4/11/14 4/11/14 4/11/14 6/11/14 7/15/14
43663463 5/12/14 5/12/14 5/12/14 9/5/14 9/17/14 . . . . .
77661437 5/16/14 . 5/16/14 . 10/31/14 . 5/16/14 5/16/14 11/16/14 .
85662295 5/29/14 . . 5/29/14 . 6/12/14 . . 11/16/14 .
36656756 6/4/14 . . . 6/4/14 6/4/14 6/12/14 6/4/14 6/4/14 12/4/14
67662646 6/14/14 . 6/14/14 8/31/14 . . 6/17/14 6/14/14 . 6/22/14
55663786 6/26/14 . . . 8/14/14 6/26/14 7/8/14 6/26/14 11/30/14 .
44663191 8/21/14 . 9/30/14 . . . . 1/12/15 . 10/31/14
;
The variables I’m trying to produce are:
Signup month (easy to do)
A count of the total number of signups for that month (easy to do)
A overall count of additional products which included with sign up
A variable which has all add on product values (transposed from original dataset).
A count of the different products purchased on the startup date
A count of add on products purchased after the signup date that were purchased in the same month of the signup date
7.Then month variables which count the additional add on products by month
If I take just April, the output I'm looking for is something like this:
data want ;
length
Sign_up_Month $5
Sign_up_count 8
Initial_Products_total 8
Products $25
Prod_Purchased_on_Signup 8
AddPro_ April_After_SU 8
May 8 June 8 July 8 August 8 September 8 October 8;
INPUT Sign_up_Month $
Sign_up_count
Initial_Products_total
Products $
Prod_Purchased_on_Signup
AddPro_ April_After_SU
May June July August September October;
datalines;
April 2 8 preferredhd_tv_estbd_dt 1
April 2 8 ultimate_estbd_dt 2
April 2 8 quant_estbd_dt 1
April 2 8 FullyLoaded_estbd_dt 1 1
April 2 8 HB_estbd_dt 1
April 2 8 Cin_estbd_dt 2
April 2 8 time_estbd_dt 2
April 2 8 router_estbd_dt 1 1
April 2 8 internet_estbd_dt 1
;
Below is the code I have for the first three vars in the output data set: signup_month, Sign_up_count, Initial_Products_total.
proc sort data=have;
by ID signup_DT; run;
proc transpose data=have out=have (drop=_LABEL_);
by ID signup_DT; run;
data have;
set have;
if signup_DT=COL1 then Initial_flag=1;run;
proc sql;
create table have as
select distinct
count( distinct ID) as Sign_up_count ,
month (signup_DT) as signup_month,
sum (Initial_flag) as Initial_Products
from have
group by month ( signup_DT) ; quit;
I'm having trouble creating the remaining vars: Prod_Purchased_on_Signup, AddPro_ April_After_SU and the counts by month.
I having been experimenting with arrays to try and accomplish this but I've been having trouble.
I'm not certain from your question what level of aggregation you want your counts to be at. But here is a solution if you are looking for summary for each distinct ID and sign-up date. This requires your original input sorted by ID signup_DT.
proc transpose
data = have
out = trans;
by ID signup_DT;
run;
/* Sort for by group processing and regular name order */
proc sort data = trans;
by ID signup_DT _NAME_;
run;
data products (drop = _NAME_ COL1 i);
set trans;
/* For by group processing */
by ID signup_DT;
/* Get the signup month as a word */
signup_month = put(signup_DT, monname.);
/* Make the product list variable to prevent truncation */
length Products $400.;
/* Retain so we can add to the variables as we go down through the group */
retain Products Sign_up_count signups_month0-signups_month4;
/* Set up array reference for later month counts so we can loop */
array som[5] signups_month0-signups_month4;
/* Reset out new variables */
if first.signup_DT then do;
Products = "";
Sign_up_count = 0;
do i = 1 to 5;
som[i] = 0;
end;
end;
/* Add to the listt and count of sign up products */
if signup_DT = COL1 then do;
Sign_up_count + 1;
Products = catx(" ", Products, _NAME_);
end;
/* Otherwise add to the later month counts by checking months seperating the dates */
else do i = 1 to 5;
if intck("month", signup_DT, COL1) = i - 1 then som[i] + 1;
end;
/* Only output once we have completed a group */
if last.signup_DT and Sign_up_count then output;
run;

Find objects with timestamp in a recurring time range

Is it possible to do a QuerySet filter that returns object form a specified, recurring time span?
For example, given a start and an end date a few days apart, I would like to be able to find:
Get all objects with timestamp between 2pm and 7pm for every day between start and end
Get all objects with timestamp between 1am and 8am for every day that is either a saturday or a sunday.
NOT TESTED
For the first case, assuming MyModel and your timestamp is called date you can do:
import datetime
start_date = datetime.date(2012,7,1)
end_date = datetime.date(2012,7,16)
start_time = datetime.time(14,0)
end_time = datetime.time(19,0)
date_range = end_date - start_date
range_list = None
for days in xrange(date_range.days):
d = start_date + datetime.timedelta(days)
if range_list is None:
range_list = Q(date__range = (datetime.datetime.combine(d, start_time), datetime.datetime.combine(d, end_time)))
else:
range_list = range_list|Q(date__range = (datetime.datetime.combine(d, start_time), datetime.datetime.combine(d, end_time)))
MyModel.objects.filter(range_list)

Resources