Posted By

Scooter on 02/07/09


Tagged

fun Star Trek


Versions (?)

Difference between two stardates


 / Published in: ASP
 

URL: http://reusablecode.blogspot.com/2009/02/difference-between-two-stardates.html

Calculates the difference between two Stardates and returns the result as a human-readable string.

  1. <%
  2. ' Copyright (c) 2009, reusablecode.blogspot.com; some rights reserved.
  3. '
  4. ' This work is licensed under the Creative Commons Attribution License. To view
  5. ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
  6. ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
  7. ' 94305, USA.
  8.  
  9. ' Calculate the difference between two stardates.
  10. function stardatediff(firstStardate, secondStardate)
  11. dim years
  12. dim years1
  13. dim years2
  14. dim days
  15. dim days1
  16. dim days2
  17. dim hours
  18. dim hours1
  19. dim hours2
  20.  
  21. years1 = mid(firstStardate, 0, 2)
  22. years2 = mid(secondStardate, 0, 2)
  23.  
  24. days1 = mid(firstStardate, 2, 3)
  25. days2 = mid(secondStardate, 2, 3)
  26.  
  27. hours1 = mid(firstStardate, 6, 1)
  28. hours2 = mid(secondStardate, 6, 1)
  29.  
  30. if years1 > years2 then
  31. years = years1 - years2
  32. else
  33. years = years2 - years1
  34. end if
  35.  
  36. if days1 > days2 then
  37. days = (days1 * 366 / 1000) - (days2 * 366 / 1000)
  38. else
  39. days = (days2 * 366 / 1000) - (days1 * 366 / 1000)
  40. end if
  41.  
  42. if hours1 > hours2 then
  43. hours = (hours1 * 144 / 60) - (hours2 * 144 / 60)
  44. else
  45. hours = (hours2 * 144 / 60) - (hours1 * 144 / 60)
  46. end if
  47.  
  48. days = round(days)
  49. hours = round(hours, 1)
  50.  
  51. stardatediff = "There are $years years, $days days, and $hours hours between Stardate $firstStardate and Stardate $secondStardate."
  52. end function
  53. %>

Report this snippet  

You need to login to post a comment.