Skip to content
Fr Simon's Secondhand Bookstall

Fr Simon's Secondhand Bookstall

Selling my books to make space (for more books)

  • Home
  • Bookstall
    • Books and other Stuff
    • Basket
    • Checkout
  • Refund and Returns Policy
  • Other things
    • Dance
    • Technology & Geekery
      • Fr Simon’s Unofficial Remote Controller
      • Easyworship Remote Control
      • get_iPlayer GUI Version 2
      • Electric Ordo (Calendar) 2023
      • jWorship
      • Development and Testing
      • NAS Drives Mapper
      • Development Privacy Policy
    • Liturgy & Worship
      • Funeral Materials
      • Common Worship RTF Files
      • Spiritual Materials
    • Blog
  • My Publications
    • MA Dissertation: Sacraments in Digital Space
  • About
  • Toggle search form

Converting TO unix datestamp in VB / VBA

Posted on June 11, 2008 By spr 2 Comments on Converting TO unix datestamp in VB / VBA

I occasionally record some tech/programming notes for the greater good of the community. If you have no idea what this means, ignore it and move onto the posts on religion…

However, if you are trying to convert a number to Unix Timestamp in VB or VBA (ie in Access), here is how it works…

I have a field which historically stores dates as an integer YYYYMMDD ie 19671008 and I need to convert it to Unix format which is number of seconds after 1st Jan 1970. Ask Google and there is such a lot of useless stuff about Unix to VB, but nothing in the other direction.

However:

Function converttoUnix(dt)

   If Len(dt) <> 8 Then dt = "19700101"

   y = Left(dt, 4)
   m = Mid(dt, 5, 2)
   d = Mid(dt, 7, 2)

   df = DateSerial(1970, 1, 1)
   dnow = DateSerial(y, m, d)

   converttoUnix = DateDiff("s", df, dnow)

End Function

Obviously, if you are converting a different format, you need to modify the lines before the DateSerial to get/extract the days, months and years. It might also be prudent to add a second to the final figure to ensure that the date is actually IN the right day and not at midnight.


		
tech

Post navigation

Previous Post: Assembly: David and Goliath
Next Post: Youth Club Talk, 13th June 2008

Related Posts

Best thirty quid I have invested for a long time… tech
Electric Ordo – Liturgical Calendar 2009 – Problem fixed for older versions of Outlook parish
Sharing a Printer Connected to an XP PC to a Vista PC – getting around "Access Denied" errors geek
Creative Liturgy: A Vision for Sacramental Mission alt.worship
Evening Prayer for Christ the King in Prezi alt.worship
Outlook woes and my final submission to Google – all made possible through GMobileSync tech

Comments (2) on “Converting TO unix datestamp in VB / VBA”

  1. Phil says:
    August 20, 2009 at 7:46 pm

    Excellent, very useful.

    Many thanks 🙂

    Reply
  2. Wilfredo Kehler says:
    December 22, 2009 at 9:02 pm

    Inspite of numerous notions, better researched articles still bring in subscribers like me. You presented complete understanding of the subject matter and my views are now complete after reading your post. Please keep up the admirable work and i will subscribe to your rss feed to be enlightened of any likely postings.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Copyright © 2023 Fr Simon's Secondhand Bookstall.

Powered by PressBook Grid Dark theme

FREE SHIPPING | CHEAPER THAN ABEBOOKS Dismiss