Convert text to mysql date format

How can i convert a date in text format into a date format that is accepted
by msql?

I have 3 values for day, month and year

I combine them to a date string $date1=$year."-".$month."-".$day;

How do i go further to make $date1 suitable for mysql?

Thanks in advance, Hennie
hennie [ Di, 16 Januar 2007 19:53 ] [ ID #1597380 ]

Re: Convert text to mysql date format

hennie wrote:

> How can i convert a date in text format into a date format that is accepted
> by msql?
>
> I have 3 values for day, month and year
>
> I combine them to a date string $date1=$year."-".$month."-".$day;
>
> How do i go further to make $date1 suitable for mysql?
>
> Thanks in advance, Hennie

Could you possibly reveal what format the data in the variables is in?
If year looks like 2006
and month looks like 05
and day looks like 09
then you are done.
Captain Paralytic [ Mi, 17 Januar 2007 11:33 ] [ ID #1598925 ]

Re: Convert text to mysql date format

hennie wrote:

> How can i convert a date in text format into a date format that is accepted
> by msql?
>
> I have 3 values for day, month and year
>
> I combine them to a date string $date1=$year."-".$month."-".$day;
>
> How do i go further to make $date1 suitable for mysql?
>
> Thanks in advance, Hennie

Could you possibly reveal what format the data in the variables is in?
If year looks like 2006
and month looks like 05
and day looks like 09
then you are done.
Captain Paralytic [ Mi, 17 Januar 2007 11:53 ] [ ID #1598926 ]

Re: Convert text to mysql date format

Post removed (X-No-Archive: yes)
Notifier Deamon [ Fr, 19 Januar 2007 19:27 ] [ ID #1601699 ]

Re: Convert text to mysql date format

Try using the PHP strtotime() function to make a UNIXTIME date, then convert
from that on the MySql side using FROMUNIXTIME (or something). StrToTime()
is a great function. Get something close to a date format and it uses it.

On 1/16/07 10:53, in article 7174d$45ad1f4a$3ec25048$9670 [at] news.chello.nl,
"hennie" <h.w.jansen [at] haarlem-nh.nl> wrote:

> How can i convert a date in text format into a date format that is accepted
> by msql?
>
> I have 3 values for day, month and year
>
> I combine them to a date string $date1=$year."-".$month."-".$day;
>
> How do i go further to make $date1 suitable for mysql?
>
> Thanks in advance, Hennie
>
>
Christopher Ames [ So, 11 März 2007 07:06 ] [ ID #1654138 ]

Re: Convert text to mysql date format

>On 1/16/07 10:53, in article 7174d$45ad1f4a$3ec25048$9670 [at] news.chello.nl,
>"hennie" <h.w.jansen [at] haarlem-nh.nl> wrote:
>
>> How can i convert a date in text format into a date format that is accepted
>> by msql?
>>
>> I have 3 values for day, month and year
>>
>> I combine them to a date string $date1=$year."-".$month."-".$day;
>>
>> How do i go further to make $date1 suitable for mysql?
>>
>> Thanks in advance, Hennie
>>
>>
>
As long as your input is numerical, you've just done it!
fox.whisper [ So, 11 März 2007 22:51 ] [ ID #1654141 ]

Re: Convert text to mysql date format

I use this for standard dates (e.g. 12-21-07)

function changeToMySqlDate($caldate){

if($caldate == ""){
return "1969-12-31";
} else {
$caldate = date('Y-m-d', strtotime($caldate));
return $caldate;
}
}



On Mar 11, 2:51 pm, fox.whis... [at] virgin.net wrote:
> >On 1/16/07 10:53, in article 7174d$45ad1f4a$3ec25048$9... [at] news.chello.nl,
> >"hennie" <h.w.jan... [at] haarlem-nh.nl> wrote:
>
> >> How can i convert a date in text format into a date format that is accepted
> >> by msql?
>
> >> I have 3 values for day, month and year
>
> >> I combine them to a date string $date1=$year."-".$month."-".$day;
>
> >> How do i go further to make $date1 suitable for mysql?
>
> >> Thanks in advance, Hennie
>
> As long as your input is numerical, you've just done it!
G-Rod [ Di, 13 März 2007 23:39 ] [ ID #1656354 ]
PHP » alt.php.sql » Convert text to mysql date format

Vorheriges Thema: Dynamic websites with reward points for members
Nächstes Thema: HELP! Importing sql file into 1&1 mysql db