hello everyone, this is my first post, so please be extra helpful, thanks. i know that you can use the time() thing to get a number which can be converted to date and time that can be understood, but can this be reversed, so that a user inputted date and time can be stored in the database as a long number, and then displayed on screen as necessary in the correct order. thanks
thanks for that, from reading that, it seems like it is exactly what i'm looking for, but i'm having trouble getting it to work. i have all the variables set up, but don't know how to convert them using this function and store the timestamp in another variable. is it possible you could give me an example of how i would do this, i haven't used used mktime() before, so don't know how to use it. everything i've tried so far results in an error because of an unexpected t_string. if you can help, it will be much apreciated.
Sure. if you have the year in $year, the month in $month, the day in $day, the hour in $hour, the minute in $minute and seconds in $second. $year = 2007; $day = 2; $month = 11; $hour = 13; $minute = 35; $second = 0; $time = mktime ( $hour, $minute, $second, $month, $day, $year); echo "Time in unix format: ".$time."<br>\n"; echo "Time in readable format: ".date('r', $time)."<br>\n"; PHP: This will output: Time in unix format: 1194006900 Time in readable format: Fri, 02 Nov 2007 13:35:00 +0100
Forget about the mktime function. Go with the strtotime function for what you want to do. $string = '10/20/2007'; $unixtimestamp = strtotime($string); PHP: Then store the $unixtimestamp.. After pulling the time stamp out from the database all you have to do is.. echo date('Y-m-d', $unixtimestamp); PHP: Way easier to mess with then the mktime function.
Beware of user-input. Having a field called date which lets your user input a string that's supposed to be a date opens you up for a heap of trouble. My favorite way of doing it is with three, or more, drop-down lists. Day, month & year. Hours and minutes if you need them. That way there will be no problems if you have users from around the world who put the the days where you would put the moths in a date.
thank you for your help everyone, i really apreciate it, also, the idea of the listboxes is a good idea, thanks for that, i'll put that into practice shortly.