Greetings, Thodoris.
In reply to Your message dated Wednesday, October 8, 2008, 16:35:40,
>> From your function name I assume you want to use it in MySQL. In that
>> case, why don't you have MySQL do all the magic for you?
>> eg. INSERT INTO table (col) VALUES (FROM_UNIXTIME($timestamp));
>> (using FROM_UNIXTIME($timestamp) will give you the date-time in "mysql
>> format" (YYYY-MM-DD HH:MM:SS) or any other format (if given via the
>> 2nd parameter)
>>
> Well I have made these two functions to solve this:
> function dateMysqlToWeb($mysqldate){
> $format = 'd/m/Y';
> $timestamp = strtotime($mysqldate);
> return date($format,$timestamp);
> }
Use SQL DATE_FORMAT instead.
Remember: Request the data you need, not the data stored.
> function dateWebToMysql($webdate){
> $format = 'Y-m-d';
> $date_part = explode("/",$webdate);
> $timestamp = mktime(0,0,0,$date_part[1],$date_part[0],$date_part[2]);
> return date($format,$timestamp);
> }
> My basic problem was how to make the user input from a form into a
> timestamp not how to use it with mysql. Since the format used here is
> dd/mm/yyyy I can't use the strtotime directly bacause as far as I know
> from the documentation I don't think that it changes with the timezone
> (as Stut suggested). So since strtotime understands all these variations
> like:
> mm/dd/yyyy, m/d/yy, mm/d/yy etc
Very basic solution: use 3 editboxes and short javascript sample to confirm
input.
Like
[__]/[__]/[____]
<span id="timeconfirm">...</span>
And fill 'timeconfirm' in onchange/onkeypress event, using verbal format like
Tue, Jan 03, 2008
That way, user actually see which date s/he have entered and you may use it
straightforward.
> I can't use this flexible behavior to get the input if it is not in the
> American format (and correct me if I am wrong). If I explode I will have
> to use the fixed format dd/mm/yyyy and I can't use other input formats
> beside this so I lose this flexible approach.
> It does work for me now but I was wondering if there was a way to avoid
> this.
Not as I know. So, you should either force user to use specific format
(military YYYY-MM-DD HH:MM:SS for example) or leave user no chance to enter
wrong data.
--
Sincerely Yours, ANR Daemon <[EMAIL PROTECTED]>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php