Using Crystal Report employee in out time calculation - sql-server

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

Related

Difference between month calculator in salesforce formula field

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)

get Dates In Range in rescript and Daylight Saving Time

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 ?

C beginner help : day of week for any given date

The prompt is:
Implement a function that reads in a string containing a textual description of a cal- endar date and that prints out the corresponding day of the week (Monday–Sunday). The two valid input formats for this function are:
mm/dd/yyyy
Example: 03/04/2014
Output: Tuesday
Month dd, yyyy
Example: March 04, 2014
Output: Tuesday
where dd is the numeric day, mm is the numeric month, yyyy is the year and Month is the name of the month. All days and months are specified using two digits (i.e. for March, use 03 instead of 3). In the second valid format, there is a single space between Month and dd and between dd, and yyyy.
In order to receive full credit on this task, your program should print out the correct day of the week for any input in a correct format.
So as of right now i am able to get the correct days for every single day except in the years 2005 2009 2013 2017 etc etc... they are always a day behind, i notice that its going by a trend of every 4 years the days end up 1 day behind. Im not sure whats wrong. is it cause my method of using 365.25 as each year is wrong?
My code:
#include<stdio.h>
int main()
{
int month,day1,day2,totdays,year,dm,dn,leap,rmd;
printf(" ");
scanf("%d/%d/%d",&month,&day1,&year);
if(((year%4==0) && (year%100!=0)) || (year%400==0))
{
if(month==1)
dm=0;
if(month==2)
dm=31;
if(month==3)
dm=60;
if(month==4)
dm=91;
if(month==5)
dm=121;
if(month==6)
dm=152;
if(month==7)
dm=182;
if(month==8)
dm=213;
if(month==9)
dm=244;
if(month==10)
dm=274;
if(month==11)
dm=305;
if(month==12)
dm=335;
}
else
{
if(month==1)
dm=0;
if(month==2)
dm=31;
if(month==3)
dm=59;
if(month==4)
dm=90;
if(month==5)
dm=120;
if(month==6)
dm=151;
if(month==7)
dm=181;
if(month==8)
dm=212;
if(month==9)
dm=243;
if(month==10)
dm=273;
if(month==11)
dm=304;
if(month==12)
dm=334;
}
day2=(year-1970)*(365.25);
dn=dm+day1;
totdays=day2+dn;
rmd=totdays%7;
if(rmd==5)
{
printf("Monday \n");
}
if(rmd==6)
{
printf("Tuesday \n");
}
if(rmd==0)
{
printf("Wednesday \n");
}
if(rmd==1)
{
printf("Thursday \n");
}
if(rmd==2)
{
printf("Friday \n");
}
if(rmd==3)
{
printf("Saturday \n");
}
if(rmd==4)
{
printf("Sunday \n");
}
return 0;
}
1969 wasn't a leap year, 1972 was. When you do
day2=(year-1970)*(365.25);
to discover how many days off January 1st of year year is, you'll count
0 days for '70
365.25 days for '71
730.5 days for '72
1095.75 days for '73
1461 days for '74
The fractional portion of the floating point calculation is truncated, so day2 isn't going to count the extra day from 02/29/1972 until 01/01/1974, instead of 01/01/1973 as it should.
Put another way, you are making the assumption that 1970 was the first year after a leap year, so a leap day won't be counted until four years later.
The day2 calculation won't work. There are 1461 days in every four year period. First you need to compute how many 4 year periods have passed. Then figure out how many days there were to the beginning of the specified year, similar to what you did for the months.
The year%100 and year%400 exceptions add a little complexity, but fortunately the year 2000 was a leap year, so the first time you have to deal with that little wrinkle is the year 2100.

Smarty - scope of dates

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}

Change Date value from one TimeZone to another TimeZone

my case is I have a Date obj the date inside is UTC time. However I want it to be changed to Japan time.
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("Japan"));
calendar.setTime(someExistingDateObj);
System.out.println(String.valueOf(calendar.get(Calendar.HOUR_OF_DAY)) + ":" + calendar.get(Calendar.MINUTE));
the existingDateObj is mapped from db and db value is 2013-02-14 03:37:00.733
04:37
it seems the timezone is not working?
thanks for your time....
Your problem may be that you're looking at things wrong. A Date doesn't have a time zone. It represents a discrete moment in time and is "intended to reflect coordinated universal time". Calendars and date formatters are what get time zone information. Your second example with the Calendar and TimeZone instances appears to work fine. Right now, this code:
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("Japan"));
System.out.println(String.valueOf(calendar.get(Calendar.HOUR)) + ":" + calendar.get(Calendar.MINUTE));
}
Reports:
0:32
That appears correct to me. What do you find wrong with it?
Update: Oh, perhaps you're expecting 12:32 from the above code? You'd want to use Calendar.HOUR_OF_DAY instead of Calendar.HOUR for that, or else do some hour math. Calendar.HOUR uses 0 to represent both noon and midnight.
Update 2: Here's my final attempt to try to get this across. Try this code:
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("H:mm a Z");
List<TimeZone> zones = Arrays.asList(
TimeZone.getTimeZone("CST"),
TimeZone.getTimeZone("UTC"),
TimeZone.getTimeZone("Asia/Shanghai"),
TimeZone.getTimeZone("Japan"));
for (TimeZone zone : zones) {
calendar.setTimeZone(zone);
format.setTimeZone(zone);
System.out.println(
calendar.get(Calendar.HOUR_OF_DAY) + ":"
+ calendar.get(Calendar.MINUTE) + " "
+ (calendar.get(Calendar.AM_PM) == 0 ? "AM " : "PM ")
+ (calendar.get(Calendar.ZONE_OFFSET) / 1000 / 60 / 60));
System.out.println(format.format(calendar.getTime()));
}
}
Note that it creates a single Calendar object, representing "right now". Then it prints out the time represented by that calendar in four different time zones, using both the Calendar.get() method and a SimpleDateFormat to show that you get the same result both ways. The output of that right now is:
22:59 PM -6
22:59 PM -0600
4:59 AM 0
4:59 AM +0000
12:59 PM 8
12:59 PM +0800
13:59 PM 9
13:59 PM +0900
If you used Calendar.HOUR instead of Calendar.HOUR_OF_DAY, then you'd see this instead:
10:59 PM -6
22:59 PM -0600
4:59 AM 0
4:59 AM +0000
0:59 PM 8
12:59 PM +0800
1:59 PM 9
13:59 PM +0900
It correctly shows the current times in Central Standard Time (my time zone), UTC, Shanghai time, and Japan time, respectively, along with their time zone offsets. You can see that they all line up and have the correct offsets.
sdf2 and sdf3 are equaly initialized, so there is no need for two of them.

Resources