Read/write epoch to RFID card

Working with an uno and MFRC522 board. I've gone through librairies and managed to read and write info to a Mifare card. Looking at writing epoch to a block and then comparing to an expiry time. Little out of my scope of programming. Can someone lend a hand? I would appreciate the help or a link to explain how. Thank you gurus. I have an DS3231 board connected also to keep current time.

'epoch' is generally a date and time in seconds (or other time interval like milliseconds) from a known starting date and time.

What do you store on the card? Do you store the expiration date and time? Do you store the issue date and time on the card and the expiration is a fixed number of days, hours, minutes, and seconds from then? Either way works. It's just simple math after that.

Thanks for reply John. The card will be valid for 30 days or 1 hour depending on issued card type. I want to write epoch (now()) to one block and when card is scanned, will compare current date and time for verification. So let's say epoch written at 1500000000 it will expire at 1502592000 thirty days later. If I can get that part figured out, I'll use same process for an hour.

Pickydesignz:
Thanks for reply John. The card will be valid for 30 days or 1 hour depending on issued card type. I want to write epoch (now()) to one block and when card is scanned, will compare current date and time for verification. So let's say epoch written at 1500000000 it will expire at 1502592000 thirty days later. If I can get that part figured out, I'll use same process for an hour.

Looks right to me.
Unless you want people to be able to change the issue date of their cards you should probably put in some kind of check to make sure that the date information has not been changed. Ideally you would use a cryptographic signature where the only way to sign the data is by knowing a private key. For medium security you could do a hash/checksum that includes data known to your software but not put on the card. I hope each card has an unchangeable serial number that you can include in the checksum/hash. Otherwise one person could get a new 30-day card and write the new expiration date and checksum to all their friend's cards.

So I can write date/time to block and read it but how do I convert date/time to an epoch time when read? That's the problem I'm facing.

So I can write date/time to block and read it but how do I convert date/time to an epoch time when read? That’s the problem I’m facing.

I would use the Time Library. There are probably several ways to get at what you want, but I would use
setTime(int hr,int min,int sec,int day, int month, int yr); and then get the epoch time with now()

#include <TimeLib.h>
void setup() {
  Serial.begin(115200);
  setTime(10, 35, 45, 14, 10, 2018);
  Serial.print("Unix Time Conversion ");
  Serial.println(now());
 }
 void loop() {}

Alright, I figured out the read/write process for the Mifare cards. I write year,month,day,hour,minute,second to the card. That is the "transfer" time (working on a transit bus pass system where the transfer is valid for one hour). When the card is swiped again, I am trying to convert the "transfer" time to compare it with the "now()" time. I tried declaring the transfer_expire time as long unsigned int.

If I use this calculation, it's off, but works every time.

transfer_expire=((transfer_year36586400)+(transfer_month3086400)+(transfer_day86400)+(transfer_hour3600)+(transfer_minute*60)+(transfer_second))

So, to account for leap year and 31 day months, I added a couple decimals like this and it errors.

transfer_expire=((transfer_year365.2586400)+(transfer_month30.0386400)+(transfer_day86400)+(transfer_hour3600)+(transfer_minute*60)+(transfer_second))

Error meaning, it reads time from card and calculates correctly, but then transfer_expire never recalculates. It reads and writes correct variables to and from rfid card, but never changes the value of transfer_expire. If I omit the decimals, it all works and recalculates fine. I'm thinking it might be something to do with variable declaration long unsigned transfer_expire but I've never played around with epoch time this way, hope someone else has. I'm on my phone and can't find coding tags, sry for the mess.

Look at the TimeLib library, to see how to properly convert a date/time vale to a unix time, and back. It does NOT involve decimals. It involves if statements.

Working with an uno and MFRC522 board.
I have an DS3231 board connected also to keep current time.

Are you using a DS3231 library? Are you using the Time Library?

If you were using the Time Library synchronized to the RTC with setSynchProvider(), then the transfer end time written to the card is simply now() + transfer window (3600 for 1 hour or 86400 for 24 hours).

Then when the card is read at a later time now() is just tested against the stored end time written on the card.