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 a free trial version of Lotus Quickr 8.0, which enables collaboration by transforming the way everyday business content such as documents, rich media, photos, and video can be shared. Lotus Quickr makes it faster and easier to share content of all types (not just documents) within virtual teams. It is designed to make it easier to collaborate across organizational boundaries, while continuing to work within the context of familiar desktop applications. FREE! Go There Now!
| | | | Download a free trial version of IBM Rational Developer for System z, software that can help you deliver core development capabilities; the power of Java Platform, Enterprise Edition (Java EE); and rapid application development support to diverse enterprise application development teams. With comprehensive development tools to help create, deploy and maintain traditional enterprise and composite applications, Rational Developer for System z enables developers with different technical backgrounds to easily participate in important technology projects. FREE! Go There Now!
| | | | As systems increase in complexity, communication between systems and software teams becomes more and more difficult. Now, there’s a way to improve product quality and communication.<br />Read the “Model Driven Systems Development” white paper to see how. Also included in this kit are more educational white papers, customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems.<br /> FREE! Go There Now!
| | | | Ken Krugler, co-founder of code search company Krugle, and Laura Merling, vice president of Marketing and Business Development for Krugle, join to talk about the ins and outs of code search and what it means as a new feature for developerWorks users. 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!
| | | | 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 Performance Tester V7.0.1, a load and performance testing solution for teams concerned about the scalability of their Web-based applications. Combining multiple ease-of-use features with granular detail, Rational Performance Tester simplifies the test-creation, load-generation and data-collection processes that help teams ensure the ability of their applications to accommodate required user loads. FREE! Go There Now!
| | | | The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size. FREE! Go There Now!
| | | | User communities play an important role in communication and collaboration around products, solutions and other areas of special interest to members. Successful communities are able to provide the right mix of content and services to deliver a value proposition that resonates with each audience. Join Tom Inman, VP of Marketing for Information and Platform Solutions as he introduces the new LeverageINFORMATION community. During this webcast, learn about the value provided by the community and how customers and partners derive value from the community in addressing their own technical and business challenges. FREE! Go There Now!
| | | | WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |
| | | | | | | |  | | | |