This method is used to simulate the VBScript DateDiff Function. It is in Beta right now.
| I have not yet implemented all of the parameters to the method, just the more commone ones
| If you find any problems please email me with a description of the issue.
|
| | 0. |
| | 1. | /// <summary> | | 2. | /// same common params as the VBScript DateDiff: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsfctdatediff.asp | | 3. | /// /*Sample Code: | | 4. | /// * System.DateTime dt1 = new System.DateTime(1974,12,16); | | 5. | /// * System.DateTime dt2 = new System.DateTime(1973,12,16); | | 6. | /// * Page.Response.Write(Convert.ToString(DateDiff("t", dt1, dt2))); | | 7. | /// * */ | | 8. | /// </summary> | | 9. | /// <param name="howtocompare"></param> | | 10. | /// <param name="startDate"></param> | | 11. | /// <param name="endDate"></param> | | 12. | /// <returns></returns> | | 13. | private double DateDiff(string howtocompare, System.DateTime startDate, System.DateTime endDate) { | | 14. | double diff=0; | | 15. | try { | | 16. | System.TimeSpan TS = new System.TimeSpan(startDate.Ticks-endDate.Ticks); | | 17. | #region converstion options | | 18. | switch (howtocompare.ToLower()) { | | 19. | case "m": | | 20. | diff = Convert.ToDouble(TS.TotalMinutes); | | 21. | break; | | 22. | case "s": | | 23. | diff = Convert.ToDouble(TS.TotalSeconds); | | 24. | break; | | 25. | case "t": | | 26. | diff = Convert.ToDouble(TS.Ticks); | | 27. | break; | | 28. | case "mm": | | 29. | diff = Convert.ToDouble(TS.TotalMilliseconds); | | 30. | break; | | 31. | case "yyyy": | | 32. | diff = Convert.ToDouble(TS.TotalDays/365); | | 33. | break; | | 34. | case "q": | | 35. | diff = Convert.ToDouble((TS.TotalDays/365)/4); | | 36. | break; | | 37. | default: | | 38. | //d | | 39. | diff = Convert.ToDouble(TS.TotalDays); | | 40. | break; | | 41. | } | | 42. | #endregion | | 43. | } catch(Exception e) { | | 44. | diff = -1; | | 45. | } | | 46. | return diff; | | 47. | } | | 48. |
|
|
|
References:
| VBScript DateDiff Function
|
| Copy Source: |
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More ASP.NET Articles More By aspfree developerWorks - FREE Tools! | Visit IBM developerWorks to download the latest trial version of IBM Data Studio V1.1 at no cost. IBM Data Studio is a comprehensive data management solution that helps you effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life cycle utilizing a consistent and integrated user interface. Unlike other client-side data management solutions that focus on only one aspect of the application lifecycle or database administration, Data Studio complements the Rational Software Delivery platform, providing unparalleled flexibility for a heterogeneous data server environment across platforms. FREE! Go There Now!
| | | | Discover how IBM Rational AppScan Standard Edition can help you detext vulnerabilities in your web applications in the Web Application Security eKit. IBM Rational AppScan is a leading suite of automated web application security solutions that scan and test for common Web application vulnerabilities. The new Web Application Security eKit provides you with valuable resources, including white papers, demos, and additional information on the benefits of testing your Web applications. FREE! Go There Now!
| | | | Visit IBM developerWorks to download a free trial version of IBM Rational Business Developer V7.1. Rational Business Developer offers rapid and simplified development of business applications and services through Enterprise Generation Language (EGL) tools, generating Java or mainframe solutions while shielding developers from technical complexities. FREE! Go There Now!
| | | | Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered! FREE! Go There Now!
| | | | As organizations have grown increasingly dependent on online software, the risk of malicious attacks has also become far more serious. Fortunately, well-governed organizations can protect their Web applications by injecting vulnerability assessments and ethical hacks into their software development and delivery processes. This paper describes 12 of the most common hacker attacks and provides basic rules that you can follow to help create more hack-resistant Web applications. FREE! Go There Now!
| | | | Get a free trial download of the latest version of IBM Rational Functional Tester V7.0.1. Rational Functional Tester is an automated functional and regression testing solution for QA teams concerned with the quality of their Java, Microsoft Visual Studio .NET, and Web-based applications. FREE! Go There Now!
| | | | In this webcast, IBM Rational will discuss the importance of Web application security and will share techniques and best practices to introduce application security testing into current QA processes including: understanding common security vulnerabilities and techniques to integrate security testing with defect tracking and remediation systems in an effort to safeguard sensitive online information. FREE! Go There Now!
| | | | In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications. FREE! Go There Now!
| | | | The unprecedented scope of a service-oriented architecture (SOA) initiative brings to the forefront a number of management and governance issues that were sidestepped in the past. The key to a successful SOA implementation is managing and governing activities throughout the entire SOA delivery lifecycle by ensuring that services conform to the needs of all of the business’s stakeholders. Learn how service lifecycle management allows the business to ensure that the process by which services are defined, created, tested, deployed, optimized and retired is manageable, repeatable and auditable. FREE! Go There Now!
| | | | With IBM Rational Systems Development Solution, you can deliver products faster with higher quality. Within this kit, Read the “Model Driven Systems Development” white paper to see how to improve product quality and communication. Then check out the rest of the e-Kit to learn more about important topics that can affect the success of any software project through customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems. From start to finish, at every stage in your projects, Rational Systems Development Solution can help your company reach its full potential. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |
| | | | | | | |  | | | |