date-math

C# Method to sum hh:mm data ???

点点圈 提交于 2019-12-01 18:05:48
I want a method that will sum data that is string in the format hh:mm (time hours and minutes) 0:15 + 0:15 = 0:30 Convert the strings to TimeSpan s and then call the .Add method. TimeSpan s1 = TimeSpan.Parse("0:15"); TimeSpan s2 = TimeSpan.Parse("0:45"); TimeSpan s3 = s1 + s2; // not tested; should work. Ref: http://msdn.microsoft.com/en-us/library/system.timespan.aspx 来源: https://stackoverflow.com/questions/2871557/c-sharp-method-to-sum-hhmm-data

Calculate age (jQuery or PHP) based on date of birth [not based on user input]

拜拜、爱过 提交于 2019-12-01 11:16:50
问题 I am looking for a JavaScript or PHP script that allows me to calculate somebody's age based on his/her date of birth in the mm/dd/yyyy format. I found this very helpful link "Calculate age in JavaScript" but it seems to be designed to work with user input. However, I am creating a page where I put the DOB directly into the HTML as simple text. Is it then still possible to calculate the age? Basically, I want this line of text to be the end-result: 29 (10/17/1983) with the value of 29 being

easy way to add 1 month to a time_t in C/C++

左心房为你撑大大i 提交于 2019-12-01 05:21:49
I have some code that uses the Oracle function add_months to increment a Date by X number of months. I now need to re-implement the same logic in a C / C++ function. For reasons I don't want/need to go into I can't simply issue a query to oracle to get the new date. Does anyone know of a simple and reliable way of adding X number of months to a time_t? Some examples of the types of calculations are shown below. 30/01/2009 + 1 month = 28/02/2009 31/01/2009 + 1 month = 28/02/2009 27/02/2009 + 1 month = 27/03/2009 28/02/2009 + 1 month = 31/03/2009 31/01/2009 + 50 months = 31/03/2013 Method

easy way to add 1 month to a time_t in C/C++

ⅰ亾dé卋堺 提交于 2019-12-01 02:54:25
问题 I have some code that uses the Oracle function add_months to increment a Date by X number of months. I now need to re-implement the same logic in a C / C++ function. For reasons I don't want/need to go into I can't simply issue a query to oracle to get the new date. Does anyone know of a simple and reliable way of adding X number of months to a time_t? Some examples of the types of calculations are shown below. 30/01/2009 + 1 month = 28/02/2009 31/01/2009 + 1 month = 28/02/2009 27/02/2009 + 1

Simple way to handle time in C#?

坚强是说给别人听的谎言 提交于 2019-11-29 07:27:13
My current approach is something like DateTime startHour = new DateTime(1900,1,1,12,25,43); DateTime endHour = new DateTime(1900,1,1,13,45,32); // I need to, say, know if a complete DateTime instance // is later than startHour plus 15 minutes DateTime now = DateTime.Now(); startHour = startHour.addMinutes(15); if (now.CompareTo(new DateTime(now.Year, now.Month, now.Day, startHour.Hour, startHour.Minute, startHour.Second)) > 0) { //I can do something now } This is very cumbersome and even failure prone. TimeSpans are not a solution as far as I can see, because they represent spans and aren't

Comparing dates in rails

只谈情不闲聊 提交于 2019-11-29 05:25:50
Suppose I have a standard Post.first.created_at datetime. Can I compare that directly with a datetime in the format 2009-06-03 16:57:45.608000 -04:00 by doing something like: Post.first.created_at > Time.parse("2009-06-03 16:57:45.608000 -04:00") Edit: Both fields are datetimes , not dates . Yes, you can use comparison operators to compare dates e.g.: irb(main):018:0> yesterday = Date.new(2009,6,13) => #<Date: 4909991/2,0,2299161> irb(main):019:0> Date.today > yesterday => true But are you trying to compare a date to a datetime? If that's the case, you'll want to convert the datetime to a date

calc the working hours between 2 dates in PHP

时光怂恿深爱的人放手 提交于 2019-11-27 15:45:31
I have a function to return the difference between 2 dates, however I need to work out the difference in working hours, assuming Monday to Friday (9am to 5:30pm): //DATE DIFF FUNCTION // Set timezone date_default_timezone_set("GMT"); // Time format is UNIX timestamp or // PHP strtotime compatible strings function dateDiff($time1, $time2, $precision = 6) { // If not numeric then convert texts to unix timestamps if (!is_int($time1)) { $time1 = strtotime($time1); } if (!is_int($time2)) { $time2 = strtotime($time2); } // If time1 is bigger than time2 // Then swap time1 and time2 if ($time1 >

calc the working hours between 2 dates in PHP

风格不统一 提交于 2019-11-27 04:07:00
问题 I have a function to return the difference between 2 dates, however I need to work out the difference in working hours, assuming Monday to Friday (9am to 5:30pm): //DATE DIFF FUNCTION // Set timezone date_default_timezone_set("GMT"); // Time format is UNIX timestamp or // PHP strtotime compatible strings function dateDiff($time1, $time2, $precision = 6) { // If not numeric then convert texts to unix timestamps if (!is_int($time1)) { $time1 = strtotime($time1); } if (!is_int($time2)) { $time2

php Object of class DateInterval could not be converted to string

送分小仙女□ 提交于 2019-11-26 17:23:06
问题 i've tried using date_diff and date_create to get a difference from two date that's already converted to string. here's the code: $date_1 = date_create(); $date_now = date_format($date_1, 'Y-m-d'); //echo $date_now . "\n"; $date=date_create($date_now); date_add($date,date_interval_create_from_date_string("3 days")); $date_return = date_format($date,"Y-m-d"); $diff = date_diff(date_create($date_now), date_create($date_return)); echo $diff; and i am getting this error: Object of class

Best way to find the months between two dates

杀马特。学长 韩版系。学妹 提交于 2019-11-26 11:44:22
I have the need to be able to accurately find the months between two dates in python. I have a solution that works but its not very good (as in elegant) or fast. dateRange = [datetime.strptime(dateRanges[0], "%Y-%m-%d"), datetime.strptime(dateRanges[1], "%Y-%m-%d")] months = [] tmpTime = dateRange[0] oneWeek = timedelta(weeks=1) tmpTime = tmpTime.replace(day=1) dateRange[0] = tmpTime dateRange[1] = dateRange[1].replace(day=1) lastMonth = tmpTime.month months.append(tmpTime) while tmpTime < dateRange[1]: if lastMonth != 12: while tmpTime.month <= lastMonth: tmpTime += oneWeek tmpTime = tmpTime