Add Column from another datatable - asp.net

I am having two Datatables : dt1 and dt2. Now dt1 is having datacolumn something like:
Monday | Wednesday | Thursday
but doesnt have anything in datarow yet.
Now,in dt2,the data is something like:
StartTime | EndTime
7:10 | 8:00
8:00 | 9:00
9:00 | 10:00
I want to merge both datatable so that i can get Datatable something like:
StartTime | EndTime | Monday | Wednesday | Thursday
7:10 | 8:00
8:00 | 9:00
9:00 | 10:00
Please help me :(
This project is to design School timetable.
Any help will be appreciated.
Thanks
Also,,,suggest me that is it good to use datatable?or should go for table control for Timetable

you can copy the columns without rows like this:
foreach (DataColumn dc in dt1.Columns)
{
dt2.Columns.Add(dc.ColumnName, dc.DataType);
}

Related

How to convert epoch time to human readable date in presto with time zone as IST

I have a column in a table which stores epoch time.
I want to convert it human readable date time stamp with time zone as IST. I am using the below query, but conversion is incorrect, it is showing 05:30 previous time.
presto:default> select to_char(date_trunc('hour',
from_unixtime((CAST(substr(startdatetime,1,10) AS double )))),
'dd-mm-yyyy hh24'),startdatetime FROM rocmetricsolr limit 10;
_col0 | startdatetime
---------------+---------------
NULL | NULL
21-05-2018 23 | 1526905879116
21-05-2018 23 | 1526905879116
21-05-2018 23 | 1526905874892
NULL | NULL
21-05-2018 23 | 1526905876216
21-05-2018 23 | 1526905876216
21-05-2018 23 | 1526905873640
21-05-2018 23 | 1526905873640
21-05-2018 23 | 1526905903110
Assume you have a table rocmetricsolr with column startdatetime in varchar type where first 10 digits present epoch timestamp:
SELECT
from_unixtime(CAST(substr(startdatetime,1,10) AS bigint)) AT TIME ZONE 'America/Los_Angeles'
Note: Please change the timezone names based on https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

MS Access date diff from one row and previous row of different fields

I need to find the difference in weeks from marked Previous End Date and next Start Date.
Visit Type | Start Date | End Date | Weeks since previous visit
------------+---------------+---------------+------------------------------
Check-Up | 19-Jan-15 | 19-Feb-15 |
Check-Up | 27-Jan-15 | 27-Jan-15 | xxx
Check-Up | 22-Jan-15 | 22-Feb-15 |
Check-Up | 21-Jan-15 | 21-Jan-1 |
I need to find the diff bw 19 feb of End date and 27 jan of Start date . A simple datediff is not working. can someone help now ?

SQLite subtract time difference between two tables if there is a match

I need some help with a SQLite Query. I have two tables, a table called 'production' and a table called 'pause':
CREATE TABLE production (
date TEXT,
item TEXT,
begin TEXT,
end TEXT
);
CREATE TABLE pause (
date TEXT,
begin TEXT,
end TEXT
);
For every item which is produced, an entry in the table production with the current date, the start time and the end time (two timestamps in the format HH:MM:SS) is created. So let's assume, the production table looks like:
+------------+-------------+------------+----------+
| date | item | begin | end |
+------------+-------------+------------+----------+
| 2013-07-31 | Item 1 | 06:18:00 | 08:03:05 |
| 2013-08-01 | Item 2 | 06:00:03 | 10:10:10 |
| 2013-08-01 | Item 1 | 10:30:15 | 14:20:13 |
| 2013-08-01 | Item 1 | 15:00:10 | 16:00:00 |
| 2013-08-02 | Item 3 | 08:50:00 | 15:00:00 |
+------------+-------------+------------+----------+
The second table also contains a date and a start and an end time. So let's assume, the 'pause' table looks like:
+------------+------------+----------+
| date | begin | end |
+------------+------------+----------+
| 2013-08-01 | 08:00:00 | 08:30:00 |
| 2013-08-01 | 12:00:00 | 13:30:00 |
| 2013-08-02 | 10:00:00 | 10:30:00 |
| 2013-08-02 | 13:00:00 | 14:00:00 |
+------------+------------+----------+
Now I wanna get a table, which contains the time difference between the production begin and end time for every item. If there is a matching entry in the 'pause' table, the pause time should be subtracted.
So basically, the end result should look like:
+------------+------------+-------------------------------------------------+
| date | Item | time difference (in seconds), excluding pause |
+------------+------------+-------------------------------------------------+
| 2013-07-31 | Item 1 | 6305 |
| 2013-08-01 | Item 1 | 12005 |
| 2013-08-01 | Item 2 | 13207 |
| 2013-08-02 | Item 3 | 16800 |
+------------+------------+-------------------------------------------------+
I am not really sure, how I can accomplish it with SQLite. I know that it is possible to do this sort of calculation with Python, but in the end I think it would be better to let the database do the calculations. Maybe someone of you could give me a hint on how to solve this problem. I tried different queries, but I always ended up with different results than I expected.
To convert a time string to the number of seconds, use the strftime function with the %s modifier.
(A time string without a date part will be assumed to have the date 2000-01-01, but this cancels out when computing the differences.)
To compute the pause times for a specific production record, use a correlated subquery; the total aggregate is needed to cope with zero/one/multiple matching pauses.
SELECT date,
item,
sum(strftime('%s', end) - strftime('%s', begin) -
(SELECT total(strftime('%s', end) - strftime('%s', begin))
FROM pause
WHERE pause.date = production.date
AND pause.begin >= production.begin
AND pause.end <= production.end)
) AS seconds
FROM production
GROUP BY date,
item
The best answer I found is:
SELECT
cast(
(
strftime('%s',time_arrived)-strftime('%s',time_departed)
) AS real
)/60/60 AS elapsed
FROM date AS t;
For aditional information check this blog article.

pl sql- estimate duration between timestamps

I have the table below:
ID | START | END
A | 11/2/2011 10:00 | 13/2/11 10:00
A | 15/2/2011 10:00 | 16/2/11 10:00
A | 18/2/2011 10:00 | 20/2/11 10:00
B | 11/2/2011 10:00 | 13/2/11 10:00
C | 14/2/2011 10:00 | 17/2/11 10:00
D | 19/2/2011 10:00 | 21/2/11 10:00
D | 25/2/2011 10:00 | 28/2/11 10:00
I want to estimate, for the repeated IDs (i.e. A, D) the duration between first END and next start, second END and third START and so go on, for the same IDs only. For example, for A, the desired result is:
START2: 15/2/2011 10:00 - END1: 13/2/11 10:00 = 2 days
START3: 18/2/2011 10:00 - END2: 16/2/11 10:00 = 2 days.
In addition, for the repeated IDs, i want the count of first events (in my example equals to 2, one for A and one for D), the count of middle repeated events ( in my example equals to 1, only for A) and the count of last. If i had an id with 10 appearances, i would have 1 first, 1 last and 8 middle events.
SELECT id,
start,
end,
start - lag(end) over (partition by id order by start)
FROM your_table
This assumes that the terms "first" and "previous" are defined by an order over the start column. If that is defined differently, you have to adjust the order by start part in my example.

Time/Date range grammars

I need to parse strings containing time spans such as:
Thursday 6:30-7:30 AM
December 30, 2009 - January 1, 2010
1/15/09, 7:30 to 8:30 PM
Thursday, from 6:30 to 7:30 AM
and others...
added
6:30 to 7:30
and date/times such as most any cases that Word's insert->date can generate
As I'd be extremely surprised if anything out there covers all the cases I need to cover, I'm looking for grammars to start from.
Ok, the following grammar parses anything in your example:
DTExp = Day, ['-', Day]
Day = DayExp, [[','], ['from'], TimeRange]
DayExp = WeekDay
| [Weekday], Month, DayNumber, [[','], YearNumber]
| [Weekday], MonthNumber, '/', DayNumber, ['/', YearNumber]
TimeRange = Time, [['-'|'to'] Time]
Time = HourNumber, ':', MinuteNumber, ['AM'|'PM']
WeekDay = 'monday' | 'tuesday' | ...
Month = MonthNumber | MonthName
MonthName = 'january' | 'february' | ...
DayNumber = Number
MonthNumber = Number
YearNumber = Number, ['AD'|'BC']
HourNumber = Number
MinuteNumber = Number
There is a slight problem in the grammar. If a DayExp is read, followed by a Time, and a '-', then you could expect another DayExp or another time. But this is solved by a lookahead, because if it is a time, a number is followed by a ':'.
Lets try to construct a parse tree:
Thursday 6 : 30 - 7 : 30 AM
| | | | | |
WeekDay Number : Number - Number : Number |
| -----|---- -----|-----------
| Time - Time
| ---------|---------
DayExp TimeRange
----------|-----------
Day
|
DTExp

Resources