Home > Net >  C # a DateTime two time range of problems
C # a DateTime two time range of problems

Time:04-02

Hi,

If I have two DateTime, numerical is random,

For example: 2018-08-06 07:08:00 and 2018-08-06 19:49:00

Hope through even with the following several time segments:
The 2018-08-06 07:08:00 ~ 2018-08-06 08:00:00 (in minutes)
The 2018-08-06 08:00:00 ~ 2018-08-06 00:00:00 (in hours)
The 2018-08-07 00:00:00 ~ 2018-08-07 00:00:00 (in days)
The 2018-09-01 00:00:00 ~ 2018-09-01 00:00:00 (in months)
The 2019-01-01 00:00:00 ~ 2019-01-01 00:00:00 (in years)
The 2020-01-01 00:00:00 ~ 2020-01-01 00:00:00 (in months)
The 2020-10-01 00:00:00 ~ 2020-10-01 19:00:00 (in hours)
The 2020-10-01 19:00:00 ~ 2020-10-01 19:49:00 (in minutes)

Would like to ask how to write generic writing?
Want to break up?

CodePudding user response:

Add to add minutes, hours, days, months, years, to find out,

CodePudding user response:

The
refer to the original poster weixin_44220506 response:
hello,

If I have two DateTime, numerical is random,

For example: 2018-08-06 07:08:00 and 2018-08-06 19:49:00

Hope through even with the following several time segments:
The 2018-08-06 07:08:00 ~ 2018-08-06 08:00:00 (in minutes)
The 2018-08-06 08:00:00 ~ 2018-08-06 00:00:00 (in hours)
The 2018-08-07 00:00:00 ~ 2018-08-07 00:00:00 (in days)
The 2018-09-01 00:00:00 ~ 2018-09-01 00:00:00 (in months)
The 2019-01-01 00:00:00 ~ 2019-01-01 00:00:00 (in years)
The 2020-01-01 00:00:00 ~ 2020-01-01 00:00:00 (in months)
The 2020-10-01 00:00:00 ~ 2020-10-01 19:00:00 (in hours)
The 2020-10-01 19:00:00 ~ 2020-10-01 19:49:00 (in minutes)

Would like to ask how to write generic writing?
Want to break up?


First of all, is to define a data structure table:
BegDate (start date), EndDate (deadline), BegTime (starting time), the EndTime (deadline), dtType value (type)
DtType enumeration definition:
Minutes=0,
Hours=1,
Day=2,
The month=3,
Years=4

Finally, the Suggestions of table structure is as follows:

Start date deadline starting time deadline value type
The 2020-10-01 2020-10-01 19:00:00 19:49:00 1

Such a DataTable or List set, we can do very well logic operations,

CodePudding user response:

TimeSpan ts=time1 - time2;
Then, ts. TotalHours is the total number of hours, other guess the one instance,

CodePudding user response:

reference 1/f, the wise know already should good karma response:
add to add a minute, hour, day, month, year, law can be find out,



Think of many possibilities, feel to write a lot if the else...
Don't know if this is the special keyword, want to refer to the great god of online...

CodePudding user response:

refer to the second floor morliz son hin reply:
Quote: refer to the original poster weixin_44220506 response:
hello,

If I have two DateTime, numerical is random,

For example: 2018-08-06 07:08:00 and 2018-08-06 19:49:00

Hope through even with the following several time segments:
The 2018-08-06 07:08:00 ~ 2018-08-06 08:00:00 (in minutes)
The 2018-08-06 08:00:00 ~ 2018-08-06 00:00:00 (in hours)
The 2018-08-07 00:00:00 ~ 2018-08-07 00:00:00 (in days)
The 2018-09-01 00:00:00 ~ 2018-09-01 00:00:00 (in months)
The 2019-01-01 00:00:00 ~ 2019-01-01 00:00:00 (in years)
The 2020-01-01 00:00:00 ~ 2020-01-01 00:00:00 (in months)
The 2020-10-01 00:00:00 ~ 2020-10-01 19:00:00 (in hours)
The 2020-10-01 19:00:00 ~ 2020-10-01 19:49:00 (in minutes)

Would like to ask how to write generic writing?
Want to break up?


First of all, is to define a data structure table:
BegDate (start date), EndDate (deadline), BegTime (starting time), the EndTime (deadline), dtType value (type)
DtType enumeration definition:
Minutes=0,
Hours=1,
Day=2,
The month=3,
Years=4

Finally, the Suggestions of table structure is as follows:

Start date deadline starting time deadline value type
The 2020-10-01 2020-10-01 19:00:00 19:49:00 1

Such a DataTable or List set, we can do very well logic operations,


Thank you for your patience reply, because in addition to according to the different types (points, when the day, month, year) present aggregation time section bar charts (completed),
So now I'm putting points,, day, month and year of aggregated data processing in advance and there are different statements,

Is now going to do with the Union to combine each table, and points GroupBy,, day, month and year of data out,
So we need the above 2018-08-06 07:08:00 and 2018-08-06 19:49:00 scope split into...
And then in accordance with the scope of a spin-off to use the where limit the scope of each table,

Don't know whether there is a better approach? Thank you,

CodePudding user response:

Judged by tostring obtain corresponding time format
Such as time. Tostring (" ss ")=="00"
Write a function, operations into two time

CodePudding user response:

refer to 6th floor wtnu200 response:
judged by tostring obtain corresponding time format
Such as time. Tostring (" ss ")=="00"
Write a function, operations into two time


Don't understand your meaning, can show some more?
Thank you for the

CodePudding user response:

reference 5 floor weixin_44220506 reply:
Quote: refer to the second floor morliz son hin reply:
Quote: refer to the original poster weixin_44220506 response:
hello,

If I have two DateTime, numerical is random,

For example: 2018-08-06 07:08:00 and 2018-08-06 19:49:00

Hope through even with the following several time segments:
The 2018-08-06 07:08:00 ~ 2018-08-06 08:00:00 (in minutes)
The 2018-08-06 08:00:00 ~ 2018-08-06 00:00:00 (in hours)
The 2018-08-07 00:00:00 ~ 2018-08-07 00:00:00 (in days)
The 2018-09-01 00:00:00 ~ 2018-09-01 00:00:00 (in months)
The 2019-01-01 00:00:00 ~ 2019-01-01 00:00:00 (in years)
The 2020-01-01 00:00:00 ~ 2020-01-01 00:00:00 (in months)
The 2020-10-01 00:00:00 ~ 2020-10-01 19:00:00 (in hours)
The 2020-10-01 19:00:00 ~ 2020-10-01 19:49:00 (in minutes)

Would like to ask how to write generic writing?
Want to break up?


First of all, is to define a data structure table:
BegDate (start date), EndDate (deadline), BegTime (starting time), the EndTime (deadline), dtType value (type)
DtType enumeration definition:
Minutes=0,
Hours=1,
Day=2,
The month=3,
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related