News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Converting date/time into a Unix timestamp

Started by Shadow, October 12, 2003, 10:54:07 PM

Previous topic - Next topic

Shadow

Is there a way to convert 10 Oct 03 2052 into time measured in the number of seconds since the Unix Epoch?

Thanks,
Shadow
Just do it, go Charter! [Unknown] offered me a spot on the dev team! I swear it!

"Sup foos'! I'm Marshie! Capital M and then arshie! I'm going this way!!!"


writeto

The only way I know is it have an array storing the number of seconds in a month. Having a const variable with the seconds in an hour, minute, day and a year.

Then :
Adding all the number of years since January 1, 1970 * 31536000.
Adding all the month predessing current using the array.
Adding all the days before current * 86400.
Adding the hours, minutes and seconds.
Checking for leap year for everyyear and adding 86400seconds for everyyear that was a leap year.

I do not know an easier way. If you tell me the language you need this in AND you can not do it yourself I can see if I have the time to write this for you.

Andrew

Spaceman-Spiff


writeto

Sorry I wasn't thinking this is a php scripting forum. If you are using PHP then combining mktime and date will easily accomplish this. There are also easier way to do this in various languages including C++, Basic... I was just providing a catch all.

[Unknown]

MySQL also has special stuff for it, like FROM_UNIXTIME() and UNIX_TIMESTAMP().  I love them.

-[Unknown]

writeto

Don't you find the functions in MySQL to be a little slow when using it for outside the database?

Andrew

David

Quote from: writeto on October 13, 2003, 12:12:55 AM
Don't you find the functions in MySQL to be a little slow when using it for outside the database?
I don't think he means he uses it in the middle of a PHP script to make the conversion but rather when inserting or selecting data so it is in the format that is needed.
This space for rent.

writeto

I won't make such assumptions since it is possible to use it in the middle of a php script and I have known some sloppy coders in my time.

[Unknown]

Quote from: writeto on October 13, 2003, 03:59:21 AM
I won't make such assumptions since it is possible to use it in the middle of a php script and I have known some sloppy coders in my time.

*is very, very scared...*

You're kidding, right?  I hope you don't think SMF is AT ALL coded in ANYTHING SIMILAR to that way!!

-[Unknown]

Shadow

Thank you much to your all!

And [Unknown] we all know you use MySQL to get most of the information for SMF, we know how much you hate to use the PHP commands. ;)
Just do it, go Charter! [Unknown] offered me a spot on the dev team! I swear it!

"Sup foos'! I'm Marshie! Capital M and then arshie! I'm going this way!!!"

writeto

I was just saying I don't make assumptions. I have worked on teams with Professional College Graduates (one in particular with a Computer Engineering Degree) who was the sloppiest laziest human being/coder on the planet.
This is a great story with him.

We were both working on a point of sales modification using a proprietary database structure. The point of sales had an application that would allow you to make menu entries in a text editor with certain delimiters and then run a macro(like) program to convert it. Well instead of learning there database he would output to a text file and then use a command line argument to pass the name of the file and execute the application.

For anyone who is reading this and thinks to themeselves well hey why not they know what they are doing they created the database why shouldn't he, you should grap a giant book (maybe an encyclopedia) and hit yourself as hard as you can in the head. Maybe this will knock some sense into you.

Because of this man and many like him I never make assumptions when it comes to someones elses classes, functions or programming in general, you never should.

Andrew

[Unknown]

Quote from: writeto on October 13, 2003, 09:14:17 PM
I was just saying I don't make assumptions. I have worked on teams with Professional College Graduates (one in particular with a Computer Engineering Degree) who was the sloppiest laziest human being/coder on the planet.

Yeah, well he's an academic programmer.  They're TAUGHT to be bad coders.

-[Unknown]

David

This space for rent.

writeto

Well, I have no degree and have been programming since 1994. I am quite young, and started quite young though. I was employed as a programmer while still in high school for a local company in Las Vegas, NV. Finally, I decided to go get my degree as I was having trouble moving up the ladder. It is not hard to get a job as a programmer without a degree, it is hard to become management without one. And if you want to start your own company you have to have managerial experience and that is what i want to do. So I am being forced to go through the old routine of getting a degree. I for one will say most everyone in these college programs is learning nothing but how to type. Syntax is 1% of 1% of programming. If you can't logically deduce the solution to a problem you are useless. I could train a monkey to type C++ or any high level language syntax, that is what they are producing monkeys, typing monkeys.

Andrew

[Unknown]

I couldn't agree more.  Logic classes should be a prerequisite. (is that the right word?)

-[Unknown]

writeto


Advertisement: