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! | Join this webcast, to learn how the Rational Process Library can help with compliance issues, drive process improvement, and assist in service-oriented architecture (SOA) or Agile development. We will take a peek into the Rational Process Library with content around software and systems engineering (including RUP), operations and systems management, program and portfolio management, and asset and SOA governance. FREE! Go There Now!
| | | | As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper. FREE! Go There Now!
| | | | Building a software-as-a-service solution requires addressing a few key technical challenges. In this webcast, we'll focus on the role of IBM Tivoli Directory Server and WebSphere Portlet Factory in creating a Software as a Service solution. We will demonstrate how to use Tivoli Directory Server to prevent the user population of one tenant from accessing the virtual portal and portlet components of another tenant. We will also use the dynamic profile capability of WebSphere Portlet Factory to create multiple highly customized applications from one code base. FREE! Go There Now!
| | | | Learn from the best! Find out how developers use Rational ClearCase to be more flexible, innovative and deliver higher quality code in the Rational ClearCase Power Users eKit. This complimentary eKit provides a collection of materials, like articles, whitepapers, and demos that can help you become a power user of Rational ClearCase. FREE! Go There Now!
| | | | Learn how to implement a build management system that uses and extends your existing automation technologies. This tutorial shows, step-by-step, how to install and configure IBM Rational Build Forge to manage builds for Jakarta Tomcat from source code. FREE! Go There Now!
| | | | Learn how to do more with your reusable assets with the free Rational Asset Manager eKit. The eKit includes demos on how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse. Plus you’ll find white papers and a Webcast that discuss the challenges of a Service Oriented Architecture and how Rational Asset Manager can provide quick and effective solutions. FREE! Go There Now!
| | | | Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered! FREE! Go There Now!
| | | | This whitepaper provides areas to consider when evaluating any software configuration management solution. It addresses how the IBM solutions (Rational ClearCase and Rational ClearQuest) meet the needs and requirements of both project leaders and developers to provide successful Software Change and Configuration Management. 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! | |
| | | | | | | |  | | | |