Convert date to timestamp
#8

What Bolex meant is utilizing MySQL to do the job for you. But you can also use this genius formula:

Код:
datetime_to_unix(year, month, day, hour, minute, second)
{
	new jday = 367 * year - 7 * (year + (month + 9) / 12) / 4 - 3 * ((year + (month - 9) / 7) / 100 + 1) / 4 + 275 * month / 9 + day + 1721029 - 2440588;

	return jday * 86400 + hour * 3600 + minute * 60 + second;
}
jday is the julian day (so the number of days passed since the beginning of unix), the lower part adds the day-time in seconds (which is the easiest part, as you can see).

It's working perfectly fine, respecting leap years etc.
It can be shortened a lot but you can do that yourself if you want.
Reply


Messages In This Thread
Convert date to timestamp - by BalkanEliteRP - 07.02.2018, 10:01
Re: Convert date to timestamp - by KayJ - 07.02.2018, 10:47
Re: Convert date to timestamp - by zMason - 07.02.2018, 11:01
Re: Convert date to timestamp - by Bolex_ - 07.02.2018, 11:03
Re: Convert date to timestamp - by BalkanEliteRP - 07.02.2018, 11:33
Re: Convert date to timestamp - by Bolex_ - 07.02.2018, 11:47
Re: Convert date to timestamp - by BalkanEliteRP - 07.02.2018, 12:03
Re: Convert date to timestamp - by NaS - 07.02.2018, 12:23
Re: Convert date to timestamp - by BalkanEliteRP - 07.02.2018, 13:09
Re: Convert date to timestamp - by Gammix - 07.02.2018, 14:07

Forum Jump:


Users browsing this thread: 1 Guest(s)