const string query = "SELECT worker, date_trunc('hour', created) AS created, AVG(hashrate) AS hashrate, " + "AVG(sharespersecond) AS sharespersecond FROM minerstats " +
"WHERE poolid = #poolId AND miner = #miner AND created >= #start AND created <= #end " +
"GROUP BY date_trunc('hour', created), worker " +
"ORDER BY created, worker;";
This query displays the time periods of hours.
how to make 15 minutes?
Here is one option:
date_trunc('hour', created)
+ extract(minute from created)::int / 15 * interval '15' minute
Related
I want to make a year as 1 April to 31 March with c#. If a Person input his DOB, the year changes if cross 31 March.`
//Display Window Period
DateTime winst21 = new DateTime(DateTime.Now.Year, dob.Month, dob.Day);
DateTime wind21 = winst21.AddYears(1);
Label2.Text = "Your Current IPPT Window is " + " " + winst21.ToString("dd/MM/yyy") + " " + "-" + " " + wind21.ToString("dd/MM/yyy");
I guess you just an offset of +9 or -3 months:
//Display Window Period
DateTime winst21 = new DateTime(dob.AddMonths(9).Year, dob.Month, dob.Day);
DateTime wind21 = winst21.AddYears(1);
What I tried is:
select cast(sum(datediff(second,0,totalhr))/3600 as varchar(12)) + ':' +
right('0' + cast(sum(datediff(second,0,totalhr))/60%60 as varchar(2)),2) +
':' + right('0' + cast(sum(datediff(second,0,totalhr))%60 as varchar(2)),2) as total
FROM checkinout where YEAR(date)=2019 and MONTH(date)=09 and userid=5
It giving wrong output 112:53:04 the right answer should be 116:30:04
If the totalhr column type is time and the format is hh:mm:ss,
For SQL Server: DATEADD (datepart , number , date )
SELECT DATEADD (ms, SUM (DATEDIFF (ms, '00:00:00.000', totalhr)), '00:00:00.000') AS total
FROM checkinout
WHERE
YEAR(date) = 2019 AND
MONTH(date) = 9 AND
userid = 5;
This function adds a specified number value (as a signed integer) to a specified datepart of an input date value, and then returns that modified value.
the above condition will return the calculated Date and Time but if you want just the hh:mm:ss in two digit format you can use:
SELECT FORMAT(hrs, '0#') + ':' + FORMAT(mins, '0#') + ':' + FORMAT(secs, '0#') as total FROM
(SELECT hrs + (((((mins * 60) + (secs - (secs % 60))) / 60) - ((((mins * 60) + (secs - (secs % 60))) / 60) % 60)) / 60) AS hrs,
(((mins * 60) + (secs - (secs % 60))) / 60) % 60 AS mins,
secs % 60 AS secs
FROM (
SELECT SUM(116) AS hrs, // you have to replace the number with your column
SUM(30) AS mins, // you have to replace the number with your column
SUM(04) AS secs // you have to replace the number with your column
) AS dateSplit) AS total
try running below query
SELECT cast(sum(DATEPART(HOUR,totalhr)) as varchar(max)) + ':' +
cast(sum(DATEPART(MINUTE,totalhr)) as varchar(max)) + ':' +
cast(sum(DATEPART(SECOND,totalhr)) as varchar(max)) FROM checkinout
I am currently designing a ticket system for my place of work.
Currently, I have most of it working except one small part. It is setup to automatically send it to the person that is responsible for fixing it. After it tells the user their Unique ID and the estimated date it should be finished. The only problem is People work different shifts. The things I want it to be able to do is
If a ticket is put in before the persons shift, it adjusts to the time they come in for their shift.
If a ticket is put in after a persons shift, adjusts it to the next day and the start of the persons shift.
If the ticket takes longer than the time remaining in the shift, use the time remaining in the shift and the remaining in the following day.
Be able to add time from previous tickets that are not completed and maintain the work schedule. (Currently working except maintaining work schedule)
For example:
First shift comes in at 7:00 am and someone puts in a ticket at 3:00 am, it should go to 7:00 am and than adjust the amount of time needed.
First shift leaves at 3:30pm and someone puts in a ticket at 3:00 pm that takes roughly an hour to complete, it should finish the 30 minutes in the day and go 30 minutes into the following day.
The code I currently have to try to handle this
if (DateTime.Now.AddMinutes(sum).Hour <= 8)
{
MessageBox.Show("Too early");
var now = DateTime.Now;
var tomorrow8am = now.AddDays(0).Date.AddHours(8);
double totalHours = (tomorrow8am - now).TotalHours;
MessageBox.Show("totalHours=" + totalHours);
var today8am = now.Date.AddHours(8).Hour;
EstimatedCompleteDate = DateTime.Today.Month + "/" + DateTime.Today.AddDays(0).Day + "/" + DateTime.Today.Year + " " + DateTime.Now.AddHours(totalHours).AddMinutes(timetoadd).ToLongTimeString();
MessageBox.Show(now.ToString() + Environment.NewLine + tomorrow8am.ToString() + Environment.NewLine + totalHours.ToString());
MessageBox.Show(now.AddHours(totalHours).AddMinutes(timetoadd).Hour.ToString());
if (DateTime.Now.AddHours(totalHours).AddMinutes(timetoadd).Hour > 15)
{
double hourstoadd = 0;// = timetoadd / 60;
do
{
hourstoadd++;
timetoadd = timetoadd - 60;
}
while (timetoadd > 60);
var remaining = hourstoadd;
int i = 0;
MessageBox.Show(remaining.ToString());
do
{
if (remaining > 0)
{
MessageBox.Show("Remaining1: " + remaining.ToString());
MessageBox.Show("Remaining - totalHours" + (remaining - totalHours).ToString());
i++;
EstimatedCompleteDate = DateTime.Today.Month + "/" + DateTime.Today.AddDays(i).Day + "/" + DateTime.Today.Year + " " + DateTime.Now.AddHours(totalHours + remaining).AddMinutes(timetoadd + now.Minute).ToLongTimeString();
remaining = remaining - 8;
}
}
while (remaining > 0);
please excuse the messagebox's I am using to give some feedback to me.
I want all people that there age is 27
how i calc the start and the end date?
ss.startAge = (DateTime.Now.Year - startAge).ToString() +
"-" + DateTime.Now.ToString("MM") + "-" + DateTime.Now.ToString("dd");
ss.endAge = (DateTime.Now.Year - (endAge-1)).ToString() +
"-" + DateTime.Now.ToString("MM") + "-" + DateTime.Now.ToString("dd");
i know that i need to sub 1 day but if the end age is need to be
1999-12-31 because the calc is above is give 2000-01-01 how i need to
write the code that the end age will be correct
how i calc the end date correctly?
I am trying to add ticks to a DateTime (c#), but I can't figure out why is this not working:
DateTime end = StartTime.AddTicks(timer.Interval);
Console.WriteLine(StartTime.ToLocalTime() + " + " + timer.Interval + " = " + end.ToLocalTime());
This is giving me the following output :
24/05/2014 20:47:27 + 60000 = 24/05/2014 20:47:27
So, why is end the same value than StartTime ?
FYI, I declared my variables like this :
private DateTime StartTime;
private Timer timer = new Timer();
10.000 ticks make 1ms, 60.000 ticks make 6ms, you don't display millisecond part so there is no difference in output, but values are different.
If you change your output formatting to the following (display millisecond part), then you can see the difference.
Console.WriteLine(StartTime.ToLocalTime().ToString("dd/MM/yyyy HH:mm:ss.fff") + " + " + timer.Interval + " = " + end.ToLocalTime().ToString("dd/MM/yyyy HH:mm:ss.fff"));
More about ticks: DateTime.Ticks