str_to_date equivalent in PHP
str_to_date equivalent in PHP
am 28.07.2009 18:59:09 von Goltsios Theodore
Hi gang,
I've been looking for a str_to_date (mysql) equivalent in PHP. I've
noticed that these are matching the description:
http://www.php.net/manual/en/datetime.createfromformat.php
http://www.php.net/manual/en/function.date-create-from-forma t.php
but I don't have PHP 5.3.0 installed in any of my systems to test it and
the function/method is not well documented yet. So I will have to write
a workaround this.
Has anybody tried this?
--
Thodoris
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: str_to_date equivalent in PHP
am 28.07.2009 19:03:00 von List Manager
Thodoris wrote:
> Hi gang,
> I've been looking for a str_to_date (mysql) equivalent in PHP. I've
> noticed that these are matching the description:
>
> http://www.php.net/manual/en/datetime.createfromformat.php
> http://www.php.net/manual/en/function.date-create-from-forma t.php
>
> but I don't have PHP 5.3.0 installed in any of my systems to test it and
> the function/method is not well documented yet. So I will have to write
> a workaround this.
>
> Has anybody tried this?
>
You will probably want a combination of strtotime() and date()
example:
$date = date('Y/m/d', strtotime('yesterday'));
Jim Lucas
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: str_to_date equivalent in PHP
am 28.07.2009 19:03:19 von rscrawford
2009/7/28 Thodoris :
> Hi gang,
> =A0 I've been looking for a str_to_date (mysql) equivalent in PHP. I've
> noticed that these are matching the description:
>
> http://www.php.net/manual/en/datetime.createfromformat.php
> http://www.php.net/manual/en/function.date-create-from-forma t.php
>
> but I don't have PHP 5.3.0 installed in any of my systems to test it and =
the
> function/method is not well documented yet. So I will have to write a
> workaround this.
>
> Has anybody tried this?
Does strtotime() not work for you?
--=20
Richard S. Crawford (rscrawford@mossroot.com)
http://www.mossroot.com
Publisher and Editor in Chief, Daikaijuzine (http://www.daikaijuzine.com)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: str_to_date equivalent in PHP
am 28.07.2009 19:09:46 von List Manager
Richard S. Crawford wrote:
> 2009/7/28 Thodoris :
>> Hi gang,
>> I've been looking for a str_to_date (mysql) equivalent in PHP. I've
>> noticed that these are matching the description:
>>
>> http://www.php.net/manual/en/datetime.createfromformat.php
>> http://www.php.net/manual/en/function.date-create-from-forma t.php
>>
>> but I don't have PHP 5.3.0 installed in any of my systems to test it and the
>> function/method is not well documented yet. So I will have to write a
>> workaround this.
>>
>> Has anybody tried this?
>
> Does strtotime() not work for you?
>
he is talking about to /MySQL/ date string format
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: str_to_date equivalent in PHP
am 28.07.2009 19:10:43 von Goltsios Theodore
--------------050606090406020407070302
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
> 2009/7/28 Thodoris :
>
>> Hi gang,
>> I've been looking for a str_to_date (mysql) equivalent in PHP. I've
>> noticed that these are matching the description:
>>
>> http://www.php.net/manual/en/datetime.createfromformat.php
>> http://www.php.net/manual/en/function.date-create-from-forma t.php
>>
>> but I don't have PHP 5.3.0 installed in any of my systems to test it and the
>> function/method is not well documented yet. So I will have to write a
>> workaround this.
>>
>> Has anybody tried this?
>>
>
> Does strtotime() not work for you?
>
>
Well actually it doesn't basically because I need to define the date's
format. This is because strtotime will use for this date:
7/8/2009
the *month/day/year* format but in Greece we usually write dates in
*day/**month/year* so this is causing me trouble.
I have written this in case there is an active database handler around:
function db_date2mysql($date_str,$date_format="%d/%m/%Y",$dbh=null) {
if (isset($dbh)) {
$sql = "SELECT STR_TO_DATE('$date_str','$date_format') AS `date`";
$ar = $dbh->query($sql)->fetch(PDO::FETCH_ASSOC);
return $ar['date'];
} else {
return null;
}
}
but I will need something more solid.
--
Thodoris
--------------050606090406020407070302--
Re: str_to_date equivalent in PHP
am 28.07.2009 19:15:10 von rscrawford
On Tue, Jul 28, 2009 at 10:09 AM, Jim Lucas wrote:
> Richard S. Crawford wrote:
>> 2009/7/28 Thodoris :
>>> Hi gang,
>>> =A0 I've been looking for a str_to_date (mysql) equivalent in PHP. I've
>>> noticed that these are matching the description:
>>>
>>> http://www.php.net/manual/en/datetime.createfromformat.php
>>> http://www.php.net/manual/en/function.date-create-from-forma t.php
>>>
>>> but I don't have PHP 5.3.0 installed in any of my systems to test it an=
d the
>>> function/method is not well documented yet. So I will have to write a
>>> workaround this.
>>>
>>> Has anybody tried this?
>>
>> Does strtotime() not work for you?
>>
>
> he is talking about to /MySQL/ date string format
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Hm, probably $date =3D date('Y-m-d',strtotime($string)) then.
--=20
Richard S. Crawford (rscrawford@mossroot.com)
http://www.mossroot.com
Publisher and Editor in Chief, Daikaijuzine (http://www.daikaijuzine.com)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: str_to_date equivalent in PHP
am 28.07.2009 19:32:43 von Ashley Sheridan
--=-3vG4UzxtWH2+fUtcKryh
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
On Tue, 2009-07-28 at 20:10 +0300, Thodoris wrote:
> > 2009/7/28 Thodoris :
> >
> >> Hi gang,
> >> I've been looking for a str_to_date (mysql) equivalent in PHP. I've
> >> noticed that these are matching the description:
> >>
> >> http://www.php.net/manual/en/datetime.createfromformat.php
> >> http://www.php.net/manual/en/function.date-create-from-forma t.php
> >>
> >> but I don't have PHP 5.3.0 installed in any of my systems to test it and the
> >> function/method is not well documented yet. So I will have to write a
> >> workaround this.
> >>
> >> Has anybody tried this?
> >>
> >
> > Does strtotime() not work for you?
> >
> >
> Well actually it doesn't basically because I need to define the date's
> format. This is because strtotime will use for this date:
> 7/8/2009
> the *month/day/year* format but in Greece we usually write dates in
> *day/**month/year* so this is causing me trouble.
>
> I have written this in case there is an active database handler around:
>
> function db_date2mysql($date_str,$date_format="%d/%m/%Y",$dbh=null) {
> if (isset($dbh)) {
> $sql = "SELECT STR_TO_DATE('$date_str','$date_format') AS `date`";
> $ar = $dbh->query($sql)->fetch(PDO::FETCH_ASSOC);
> return $ar['date'];
> } else {
> return null;
> }
> }
>
> but I will need something more solid.
>
I've always used strtotime from the output I get from the database, and
it's always worked for me, and before you ask, I live in the UK where
the date formats make sense :p
Thanks
Ash
www.ashleysheridan.co.uk
--=-3vG4UzxtWH2+fUtcKryh--
Re: str_to_date equivalent in PHP
am 28.07.2009 19:38:37 von Goltsios Theodore
--------------060607050506050108070706
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
> On Tue, 2009-07-28 at 20:10 +0300, Thodoris wrote:
>> > 2009/7/28 Thodoris >:
>> >
>> >> Hi gang,
>> >> I've been looking for a str_to_date (mysql) equivalent in PHP. I've
>> >> noticed that these are matching the description:
>> >>
>> >> http://www.php.net/manual/en/datetime.createfromformat.php
>> >> http://www.php.net/manual/en/function.date-create-from-forma t.php
>> >>
>> >> but I don't have PHP 5.3.0 installed in any of my systems to test it and the
>> >> function/method is not well documented yet. So I will have to write a
>> >> workaround this.
>> >>
>> >> Has anybody tried this?
>> >>
>> >
>> > Does strtotime() not work for you?
>> >
>> >
>> Well actually it doesn't basically because I need to define the date's
>> format. This is because strtotime will use for this date:
>> 7/8/2009
>> the *month/day/year* format but in Greece we usually write dates in
>> *day/**month/year* so this is causing me trouble.
>>
>> I have written this in case there is an active database handler around:
>>
>> function db_date2mysql($date_str,$date_format="%d/%m/%Y",$dbh=null) {
>> if (isset($dbh)) {
>> $sql = "SELECT STR_TO_DATE('$date_str','$date_format') AS `date`";
>> $ar = $dbh->query($sql)->fetch(PDO::FETCH_ASSOC);
>> return $ar['date'];
>> } else {
>> return null;
>> }
>> }
>>
>> but I will need something more solid.
>>
>>
> I've always used strtotime from the output I get from the database,
> and it's always worked for me, and before you ask, I live in the UK
> where the date formats make sense :p
>
>
>
> Thanks
> Ash
> www.ashleysheridan.co.uk
>
Well it does make sense if you leave in UK :-) . But I was asking about
how to change a day/month/year formated date (or a date in any format I
like) to mysql format. The basic problem is that I need to define the
format that the date is in.
Sorry if I didn't make that clear before.
--
Thodoris
--------------060607050506050108070706--
Re: str_to_date equivalent in PHP
am 28.07.2009 19:40:13 von List Manager
Thodoris wrote:
>
>> 2009/7/28 Thodoris :
>>
>>> Hi gang,
>>> I've been looking for a str_to_date (mysql) equivalent in PHP. I've
>>> noticed that these are matching the description:
>>>
>>> http://www.php.net/manual/en/datetime.createfromformat.php
>>> http://www.php.net/manual/en/function.date-create-from-forma t.php
>>>
>>> but I don't have PHP 5.3.0 installed in any of my systems to test it
>>> and the
>>> function/method is not well documented yet. So I will have to write a
>>> workaround this.
>>>
>>> Has anybody tried this?
>>>
>>
>> Does strtotime() not work for you?
>>
>>
> Well actually it doesn't basically because I need to define the date's
> format. This is because strtotime will use for this date:
> 7/8/2009
> the *month/day/year* format but in Greece we usually write dates in
> *day/**month/year* so this is causing me trouble.
>
> I have written this in case there is an active database handler around:
>
> function db_date2mysql($date_str,$date_format="%d/%m/%Y",$dbh=null) {
> if (isset($dbh)) {
> $sql = "SELECT STR_TO_DATE('$date_str','$date_format') AS `date`";
> $ar = $dbh->query($sql)->fetch(PDO::FETCH_ASSOC);
> return $ar['date'];
> } else {
> return null;
> }
> }
>
> but I will need something more solid.
>
Just a side question about your function.
Is there a PDO::FETCH_OBJECT that could be used in place of the
PDO::FETCH_ASSOC that you show.
If so, could you shorten that by one line by doing this
return $dbh->query($sql)->fetch(PDO::FETCH_OBJECT)->date;
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: str_to_date equivalent in PHP
am 28.07.2009 19:42:04 von Ashley Sheridan
On Tue, 2009-07-28 at 20:38 +0300, Thodoris wrote:
> > On Tue, 2009-07-28 at 20:10 +0300, Thodoris wrote:
> >> > 2009/7/28 Thodoris >:
> >> >
> >> >> Hi gang,
> >> >> I've been looking for a str_to_date (mysql) equivalent in PHP. I've
> >> >> noticed that these are matching the description:
> >> >>
> >> >> http://www.php.net/manual/en/datetime.createfromformat.php
> >> >> http://www.php.net/manual/en/function.date-create-from-forma t.php
> >> >>
> >> >> but I don't have PHP 5.3.0 installed in any of my systems to test it and the
> >> >> function/method is not well documented yet. So I will have to write a
> >> >> workaround this.
> >> >>
> >> >> Has anybody tried this?
> >> >>
> >> >
> >> > Does strtotime() not work for you?
> >> >
> >> >
> >> Well actually it doesn't basically because I need to define the date's
> >> format. This is because strtotime will use for this date:
> >> 7/8/2009
> >> the *month/day/year* format but in Greece we usually write dates in
> >> *day/**month/year* so this is causing me trouble.
> >>
> >> I have written this in case there is an active database handler around:
> >>
> >> function db_date2mysql($date_str,$date_format="%d/%m/%Y",$dbh=null) {
> >> if (isset($dbh)) {
> >> $sql = "SELECT STR_TO_DATE('$date_str','$date_format') AS `date`";
> >> $ar = $dbh->query($sql)->fetch(PDO::FETCH_ASSOC);
> >> return $ar['date'];
> >> } else {
> >> return null;
> >> }
> >> }
> >>
> >> but I will need something more solid.
> >>
> >>
> > I've always used strtotime from the output I get from the database,
> > and it's always worked for me, and before you ask, I live in the UK
> > where the date formats make sense :p
> >
> >
> >
> > Thanks
> > Ash
> > www.ashleysheridan.co.uk
> >
>
> Well it does make sense if you leave in UK :-) . But I was asking about
> how to change a day/month/year formated date (or a date in any format I
> like) to mysql format. The basic problem is that I need to define the
> format that the date is in.
>
> Sorry if I didn't make that clear before.
>
Why not use mktime() and date() along with a few substrings?
Thanks
Ash
www.ashleysheridan.co.uk
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: str_to_date equivalent in PHP
am 28.07.2009 19:44:53 von Goltsios Theodore
--------------000108000309080806020407
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
> Thodoris wrote:
>
>>> 2009/7/28 Thodoris :
>>>
>>>
>>>> Hi gang,
>>>> I've been looking for a str_to_date (mysql) equivalent in PHP. I've
>>>> noticed that these are matching the description:
>>>>
>>>> http://www.php.net/manual/en/datetime.createfromformat.php
>>>> http://www.php.net/manual/en/function.date-create-from-forma t.php
>>>>
>>>> but I don't have PHP 5.3.0 installed in any of my systems to test it
>>>> and the
>>>> function/method is not well documented yet. So I will have to write a
>>>> workaround this.
>>>>
>>>> Has anybody tried this?
>>>>
>>>>
>>> Does strtotime() not work for you?
>>>
>>>
>>>
>> Well actually it doesn't basically because I need to define the date's
>> format. This is because strtotime will use for this date:
>> 7/8/2009
>> the *month/day/year* format but in Greece we usually write dates in
>> *day/**month/year* so this is causing me trouble.
>>
>> I have written this in case there is an active database handler around:
>>
>> function db_date2mysql($date_str,$date_format="%d/%m/%Y",$dbh=null) {
>> if (isset($dbh)) {
>> $sql = "SELECT STR_TO_DATE('$date_str','$date_format') AS `date`";
>> $ar = $dbh->query($sql)->fetch(PDO::FETCH_ASSOC);
>> return $ar['date'];
>> } else {
>> return null;
>> }
>> }
>>
>> but I will need something more solid.
>>
>>
>
> Just a side question about your function.
>
> Is there a PDO::FETCH_OBJECT that could be used in place of the
> PDO::FETCH_ASSOC that you show.
>
> If so, could you shorten that by one line by doing this
>
> return $dbh->query($sql)->fetch(PDO::FETCH_OBJECT)->date;
>
>
>
Thanks Jim !! That is a very good suggestion.
How did I miss that :-)
--
Thodoris
--------------000108000309080806020407--
Re: str_to_date equivalent in PHP
am 28.07.2009 19:48:04 von Goltsios Theodore
--------------000705010002030909030408
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
>
>> Well it does make sense if you leave in UK :-) . But I was asking about
>> how to change a day/month/year formated date (or a date in any format I
>> like) to mysql format. The basic problem is that I need to define the
>> format that the date is in.
>>
>> Sorry if I didn't make that clear before.
>>
>>
>
> Why not use mktime() and date() along with a few substrings?
>
> Thanks
> Ash
> www.ashleysheridan.co.uk
>
>
I know that this works (as a workaround) which gets me back to my
initial question: Can I use date_create_from_format()??
Does this works the way I need (because I don't have PHP 5.3.0 to test it)?
http://www.php.net/manual/en/function.date-create-from-forma t.php
--
Thodoris
--------------000705010002030909030408--