I'm creating smarty3 code that shows the expected delivery date of a product depending on the current time and day of the week.
Tuesday -> <14:00 Friday - 14:00 Monday)
Wednesday -> <14:00 Monday - 14:00 Tuesday)
Thursday -> <14:00 Tuesday - 14:00 Wednesday)
Friday -> <14:00 Wednesday - 14:00 Thursday)
Monday -> <14:00 Thursday - 14:00 Friday)
I'm thinking of storing the list in an array where the Key is the day of the week and value is the scope.
How can I check if the current sever date corresponds with any of the scopes and how should I store the scopes in the array so that I can check the range?
In php:
$expected = time()-14*3600+2*86400;
if(date('w',$expected) ==6){
$expected+=86400;
}
if(date('w',$expected) ==0){
$expected+=86400;
}
print date('l',$expected);
In smarty:
{$expected = $smarty.now() -14*3600+2*86400}
{if date('w',$expected) ==6}
{$expected = $expected + 86400}
{/if}
{if date('w',$expected) ==0}
$expected+=86400;
{$expected = $expected + 86400}
{/if}
{$expected|date_format:%A}
Related
I have two dates
1.statdate : 12-11-2022
2.enddate. : 02-20-2023
if the start date is 1-15th day then the result should be the current month ex: mm-dd-yyyy[12-11-2022] Then December 1st
if the start date is 16th-31st day then the result should be the current month EX: mm-dd-yyyy[12-22-2022] Then January 1st.
if the EndDate is 1-15th day then the result should be the current month+1 EX: mm-dd-yyyy[02-11-2022] Then January 31st
if the EndDate is 16-31sh day then the result should be the current month+1 EX: mm-dd-yyyy[02-20-2022] Then Feb 28th
input start date result: December 1st
input end date result: Feb 28th
Result[3] which is three months from the start date to the end date.
Can we do this in the formula field? I am able to do it in apex it worked but I was unable to do it in the formula field any help would be appreciated.
ROUND(((IF(DAY(Return_To_Work__c) <= 15, DATE( YEAR(Return_To_Work__c) ,
MONTH(Return_To_Work__c) -1,(DAY(Return_To_Work__c)-
DAY(Return_To_Work__c)+
28 + MOD(((MONTH(Return_To_Work__c) -1) +
FLOOR((MONTH(Return_To_Work__c) -1)/8)), 2) + MOD(2,
(MONTH(Return_To_Work__c) -1)) + 2 * FLOOR(1/(MONTH(Return_To_Work__c)
-1))))
,IF(DAY(Return_To_Work__c) >= 16,DATE( YEAR(Return_To_Work__c)
,MONTH(Return_To_Work__c),(DAY(Return_To_Work__c)-
DAY(Return_To_Work__c)+28 + MOD(((MONTH(Return_To_Work__c)) +
FLOOR((MONTH(Return_To_Work__c))/8)), 2) + MOD(2,
(MONTH(Return_To_Work__c))) + 2 *
FLOOR(1/(MONTH(Return_To_Work__c))))),NULL)) -
IF(DAY(First_Day_Of_Leave__c) <= 15, DATE( YEAR(First_Day_Of_Leave__c)
, MONTH(First_Day_Of_Leave__c) ,(DAY(First_Day_Of_Leave__c)-
DAY(First_Day_Of_Leave__c)+1)),IF(DAY(First_Day_Of_Leave__c) >=
16,DATE( YEAR(First_Day_Of_Leave__c)
,MONTH(First_Day_Of_Leave__c)+1,(DAY(First_Day_Of_Leave__c)-
DAY(First_Day_Of_Leave__c)+1)),NULL)))/30),0)
I am making a Alarm System for Mon, Tue, Wed, Thu, Fri Sat and Sun separate. Let's say i am setting an alarm for Tuesday than i need all Tuesdays of current Month and atleast for current year till the alarm is Off. I want to achieve it using moment.
I am using Package - 'moment-weekdaysin', this is not giving me proper result. It is giving me incorrect date.
code - moment().weekdaysInMonth('Monday')
I've not used moment-weedaysin before but it should share most of the same API as core moment. The code below will capture all Tuesday dates in the format of Month-Day-Year (MM-DD-YYY) from the current date til the end of the current year. You can change the parameter for any other days 1-7 (Monday-Sunday).
import moment from 'moment';
const getOccurrencesOfDayThisYear = (day = 1) => {
let startDate = moment();
const endOfYear = moment().endOf('year');
const extractedDates = [];
while (startDate.isBefore(endOfYear)) {
if (moment(startDate).day() == day) {
extractedDates.push(moment(startDate).format('MM-DD-YYYY'));
}
startDate = moment(startDate).add(1, 'days');
}
return extractedDates;
};
// 2 represents Tuesday; 1 being Monday and 7 being Sunday
getOccurrencesOfDayThisYear(2)
There might be a more sophisticated way of performing this through various moment methods.
I have issue extracting week/year from DATE column.
We are in week 02 of 2022 and my goal is to set MAX week to be "01 2022" at the moment.
Goal is to have dynamic calculated column or measure that will always show previous week.
weekMax = FORMAT(MAX(fact[date]),"WW YYYY")
With this solution it is showing me 03 2022 result.
Is there a way to sort this out?
You could try something like:
weekMax =
VAR lastweek = FORMAT(DATEADD('Table'[Date].[Date], -7, DAY) ,"WW YYYY")
RETURN
IF(FORMAT(TODAY() - 7 ,"WW YYYY") = lastweek, lastweek, BLANK())
Output:
Or if you always just want the last week without considering any columns, you can use:
weekMax = FORMAT(TODAY() - 7 ,"WW YYYY")
i have a calendar in my site which take a start date and end date and pass them into a function who calculates the dates between .
lets sat we have the start date Mon Mar 29 2021 03:00:00 GMT+0300 (Eastern European Summer Time) and the end date is Mon Apr 05 2021 03:00:00 GMT+0300 (Eastern European Summer Time) ; this function should return ["30/3/2021","31/3/2021","1/4/2020","2/4/2020","3/4/2020","4/4/2020"]
let getDatesInRange = (start, end) => {
let dates = ref([])
let current = ref(start)
while current.contents <= end {
dates := dates.contents->Js.Array2.concat([current.contents->toUTCDateString])
current := {
let date = current.contents->toUTCDateString->Js.Date.fromString
date->Js.Date.setDate(date->Js.Date.getDate +. 1.0)->ignore
date
}
}
dates.contents
}
and this is toUTCDateString function which take a date and give the string version of it
let toUTCDateString = date => {
let date = date->External.unSafeCastToJsObject
date["toISOString"]()["split"]("T")[0]
}
These functions where working fine until The time has changed for Daylight Saving Time; we gain an hour so the day stuck there in for some reason
Any body face this issue before and who to deal with such time issues ?
I have employee attendance software and data like this
emp id Date Time
1 15/06/16 08:00 12:30 01:00 08:00
2 15/06/16 08:00 12:30 01:00 07:30
How to calculate total hours in the day using crystal reports?
For example:
emp id 1 on date 15 /06/16 total hours work day is 12 hours
and
emp id 2 on date 15/06/16 total hours work day is 11:30 hours.
Try this:
Create a formula:
Split(Totext(database.Time)," ")[1]& " "&"in time"&ChrW(13)
Split(Totext(database.Time)," ")[2]& " "&"out time"&ChrW(13)
Split(Totext(database.Time)," ")[3]& " "&"in time"&ChrW(13)
Split(Totext(database.Time)," ")[4]& " "&"out time"
Place in detail section
Edit..............
Create a formula and write below code and place after the database field:
Note: Where Database.fieldname contains 08:00 12:30 01:00 08:00 whole string
Numbervar starthour;
Numbervar startminute;
Numbervar endhour;
Numbervar endminute;
Numbervar Finalhour;
Numbervar Finalminute;
Numbervar i:=0;
starthour:=(ToNumber(Split(Split({Database.fieldname}," ")[2],":")[1]) - ToNumber(Split(Split({Database.fieldname}," ")[1],":")[1]));
endhour:=(ToNumber(Split(Split({Database.fieldname}," ")[7],":")[1]) - ToNumber(Split(Split({Database.fieldname}," ")[4],":")[1]));
startminute:=(ToNumber(Split(Split({Database.fieldname}," ")[2],":")[2]) - ToNumber(Split(Split({Database.fieldname}," ")[1],":")[2]));
endminute:=(ToNumber(Split(Split({Database.fieldname}," ")[7],":")[2]) - ToNumber(Split(Split({Database.fieldname}," ")[4],":")[2]));
if (startminute+endminute) >=60
Then
(
Finalhour:=(starthour+endhour)+1;
Finalminute:=(startminute+endminute)-60
)
else
(
Finalhour:=(starthour+endhour);
Finalminute:=(startminute+endminute)
)
;
Finalhour&":"&Finalminute