FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » how format one date
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
how format one date [message #179054] Fri, 07 September 2012 13:28 Go to next message
nawfer is currently offline  nawfer
Messages: 34
Registered: August 2011
Karma: 0
Member
if have one of this date so

Thu, 06/09/2012 - 23:50
Thursday, 6 September, 2012 - 23:50
Thu, 06/09/2012 - 23:50
06/09/2012 - 23:50

how can have this
2012-09-06T23:50:00

and finally to have the seconds 1346968200
Re: how format one date [message #179055 is a reply to message #179054] Fri, 07 September 2012 13:48 Go to previous messageGo to next message
Salvatore is currently offline  Salvatore
Messages: 38
Registered: September 2012
Karma: 0
Member
On 2012-09-07, nawfer <novalidsforspam(at)alt(dot)al> wrote:
> if have one of this date so
>
> Thu, 06/09/2012 - 23:50
> Thursday, 6 September, 2012 - 23:50
> Thu, 06/09/2012 - 23:50
> 06/09/2012 - 23:50
>
> how can have this
> 2012-09-06T23:50:00
>
> and finally to have the seconds 1346968200

I'm not sure if you're asking how to *format* a date or how to *parse* a
date. If you want to format a date, given a timestamp, use either the
date() function or the strftime() function. If you want to parse a date,
given a string, use either the strtotime() function or the strptime()
function.

--
Blah blah bleh...
GCS/CM d(-)@>-- s+:- !a C++$ UBL++++$ L+$ W+++$ w M++ Y++ b++
Re: how format one date [message #179056 is a reply to message #179055] Fri, 07 September 2012 14:56 Go to previous messageGo to next message
nawfer is currently offline  nawfer
Messages: 34
Registered: August 2011
Karma: 0
Member
Il Fri, 7 Sep 2012 13:48:29 +0000 (UTC), Salvatore ha scritto:

> On 2012-09-07, nawfer <novalidsforspam(at)alt(dot)al> wrote:
>> if have one of this date so
>>
>> Thu, 06/09/2012 - 23:50
>> Thursday, 6 September, 2012 - 23:50
>> Thu, 06/09/2012 - 23:50
>> 06/09/2012 - 23:50
>>
>> how can have this
>> 2012-09-06T23:50:00
>>
>> and finally to have the seconds 1346968200
>
> I'm not sure if you're asking how to *format* a date or how to *parse* a
> date. If you want to format a date, given a timestamp, use either the
> date() function or the strftime() function. If you want to parse a date,
> given a string, use either the strtotime() function or the strptime()
> function.

if have this string
"06/09/2012 - 23:50"

how can have this
2012-09-06T23:50:00
Re: how format one date [message #179057 is a reply to message #179056] Fri, 07 September 2012 15:10 Go to previous messageGo to next message
Salvatore is currently offline  Salvatore
Messages: 38
Registered: September 2012
Karma: 0
Member
On 2012-09-07, nawfer <novalidsforspam(at)alt(dot)al> wrote:
> if have this string
> "06/09/2012 - 23:50"
>
> how can have this
> 2012-09-06T23:50:00

Ah! I understand now. What you want to do is parse the European-style
string using strptime().

Here's a code example:

<?php
$formattedDate = '06/09/2012 - 23:50';
define('LOCAL_DATE_FORMAT', '%d/%m/%Y - %R');

// Break apart the date.
$dateArray = strptime($formattedDate, LOCAL_DATE_FORMAT);
$reformattedDate = sprintf('%04d-%02d-%02dT%02d:%02d:00', $dateArray['tm_year'] + 1900, $dateArray['tm_mon'] + 1, $dateArray['tm_mday'], $dateArray['tm_hour'], $dateArray['tm_min']);
?>

--
Blah blah bleh...
GCS/CM d(-)@>-- s+:- !a C++$ UBL++++$ L+$ W+++$ w M++ Y++ b++
Re: how format one date [message #179058 is a reply to message #179057] Fri, 07 September 2012 15:20 Go to previous messageGo to next message
nawfer is currently offline  nawfer
Messages: 34
Registered: August 2011
Karma: 0
Member
Il Fri, 7 Sep 2012 15:10:49 +0000 (UTC), Salvatore ha scritto:

> $formattedDate = '06/09/2012 - 23:50';
> define('LOCAL_DATE_FORMAT', '%d/%m/%Y - %R');
>
> // Break apart the date.
> $dateArray = strptime($formattedDate, LOCAL_DATE_FORMAT);
> $reformattedDate = sprintf('%04d-%02d-%02dT%02d:%02d:00', $dateArray['tm_year'] + 1900, $dateArray['tm_mon'] + 1, $dateArray['tm_mday'], $dateArray['tm_hour'], $dateArray['tm_min']);


I have this error
Call to undefined function strptime()

I use php 5.2.10
Re: how format one date [message #179059 is a reply to message #179058] Fri, 07 September 2012 15:39 Go to previous messageGo to next message
Salvatore is currently offline  Salvatore
Messages: 38
Registered: September 2012
Karma: 0
Member
On 2012-09-07, nawfer <novalidsforspam(at)alt(dot)al> wrote:
> I have this error
> Call to undefined function strptime()
>
> I use php 5.2.10

Are you running PHP on Windows?

--
Blah blah bleh...
GCS/CM d(-)@>-- s+:- !a C++$ UBL++++$ L+$ W+++$ w M++ Y++ b++
Re: how format one date [message #179060 is a reply to message #179056] Fri, 07 September 2012 18:07 Go to previous messageGo to next message
Tim Streater is currently offline  Tim Streater
Messages: 328
Registered: September 2010
Karma: 0
Senior Member
In article <1guuas2go7c0i$(dot)1aviei1ybpcod$(dot)dlg(at)40tude(dot)net>,
nawfer <novalidsforspam(at)alt(dot)al> wrote:

> Il Fri, 7 Sep 2012 13:48:29 +0000 (UTC), Salvatore ha scritto:
>
>> On 2012-09-07, nawfer <novalidsforspam(at)alt(dot)al> wrote:
>>> if have one of this date so
>>>
>>> Thu, 06/09/2012 - 23:50
>>> Thursday, 6 September, 2012 - 23:50
>>> Thu, 06/09/2012 - 23:50
>>> 06/09/2012 - 23:50
>>>
>>> how can have this
>>> 2012-09-06T23:50:00
>>>
>>> and finally to have the seconds 1346968200
>>
>> I'm not sure if you're asking how to *format* a date or how to *parse* a
>> date. If you want to format a date, given a timestamp, use either the
>> date() function or the strftime() function. If you want to parse a date,
>> given a string, use either the strtotime() function or the strptime()
>> function.
>
> if have this string
> "06/09/2012 - 23:50"

Use strtotime () to convert the above into seconds.

> how can have this
> 2012-09-06T23:50:00

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
Re: how format one date [message #179061 is a reply to message #179060] Fri, 07 September 2012 19:28 Go to previous messageGo to next message
bill is currently offline  bill
Messages: 310
Registered: October 2010
Karma: 0
Senior Member
On 9/7/2012 2:07 PM, Tim Streater wrote:
> In article <1guuas2go7c0i$(dot)1aviei1ybpcod$(dot)dlg(at)40tude(dot)net>,
> nawfer <novalidsforspam(at)alt(dot)al> wrote:
>
>> Il Fri, 7 Sep 2012 13:48:29 +0000 (UTC), Salvatore ha scritto:
>>
>>> On 2012-09-07, nawfer <novalidsforspam(at)alt(dot)al> wrote:
>>>> if have one of this date so
>>>>
>>>> Thu, 06/09/2012 - 23:50
>>>> Thursday, 6 September, 2012 - 23:50
>>>> Thu, 06/09/2012 - 23:50
>>>> 06/09/2012 - 23:50
>>>>
>>>> how can have this >> 2012-09-06T23:50:00
>>>>
>>>> and finally to have the seconds 1346968200
>>>> I'm not sure if you're asking how to *format* a date or how
>> to *parse* a
>>> date. If you want to format a date, given a timestamp, use
>> either the
>>> date() function or the strftime() function. If you want to
>> parse a date,
>>> given a string, use either the strtotime() function or the
>> strptime()
>>> function.
>>
>> if have this string
>> "06/09/2012 - 23:50"
>
> Use strtotime () to convert the above into seconds.
then use date() to convert it back to the format you want.


>
>> how can have this 2012-09-06T23:50:00
>
Re: how format one date [message #179062 is a reply to message #179058] Fri, 07 September 2012 20:05 Go to previous messageGo to next message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
On 07-09-2012 17:20, nawfer wrote:
> Il Fri, 7 Sep 2012 15:10:49 +0000 (UTC), Salvatore ha scritto:
>
>> $formattedDate = '06/09/2012 - 23:50';
>> define('LOCAL_DATE_FORMAT', '%d/%m/%Y - %R');
>>
>> // Break apart the date.
>> $dateArray = strptime($formattedDate, LOCAL_DATE_FORMAT);
>> $reformattedDate = sprintf('%04d-%02d-%02dT%02d:%02d:00', $dateArray['tm_year'] + 1900, $dateArray['tm_mon'] + 1, $dateArray['tm_mday'], $dateArray['tm_hour'], $dateArray['tm_min']);
>
>
> I have this error
> Call to undefined function strptime()
>
> I use php 5.2.10
>

http://php.net/manual/en/function.strptime.php
says:
strptime
(PHP 5 >= 5.1.0)

hmmm, interesting...... ;)
Re: how format one date [message #179063 is a reply to message #179061] Fri, 07 September 2012 22:19 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
bill wrote:

> On 9/7/2012 2:07 PM, Tim Streater wrote:
>> In article <1guuas2go7c0i$(dot)1aviei1ybpcod$(dot)dlg(at)40tude(dot)net>,
>> nawfer <novalidsforspam(at)alt(dot)al> wrote:
>>> Il Fri, 7 Sep 2012 13:48:29 +0000 (UTC), Salvatore ha scritto:
>>>> On 2012-09-07, nawfer <novalidsforspam(at)alt(dot)al> wrote:
>>>> > if have one of this date so
>>>> >
>>>> > Thu, 06/09/2012 - 23:50
>>>> > Thursday, 6 September, 2012 - 23:50
>>>> > Thu, 06/09/2012 - 23:50
>>>> > 06/09/2012 - 23:50
>>>> >
>>>> > how can have this >> 2012-09-06T23:50:00
>>>> >
>>>> > and finally to have the seconds 1346968200
>>>> > I'm not sure if you're asking how to *format* a date or how
>>>> > to *parse* a date. If you want to format a date, given a
>>>> > timestamp, use either the date() function or the strftime()
>>>> > function. If you want to parse a date, given a string, use
>>>> > either the strtotime() function or the strptime()
>>>> > function.
>>>
>>> if have this string
>>> "06/09/2012 - 23:50"
>>
>> Use strtotime () to convert the above into seconds.
> then use date() to convert it back to the format you want.

In this case, strptime() and strftime() should be used instead because, in
contrast to strtotime() and date(), they observe the current locale (note
the German month name above), and you get to choose the supported format
with strptime(), so there are no ambiguities with parsing.

Because in the US-American date format the month comes first (MM/DD/YYYY),
strtotime() will return the timestamp for 2012-06-09 23:50, and _not_
2012-09-06 23:50 as it was probably intended, considering today's date.
That is, if, and only if, the hyphen is removed before; else it returns
FALSE because that is not one of the formats supported by it. Tested with
PHP 5.3.10-1 (cli) (built: Feb 3 2012 10:03:01).

Both of those PHP functions are available on all platforms; strftime() since
PHP 4, strptime() since PHP 5.1.

<http://php.net/strptime>
<http://php.net/strftime>
<http://php.net/strtotime>
<http://php.net/date>


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Re: how format one date [message #179064 is a reply to message #179063] Fri, 07 September 2012 22:22 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Thomas 'PointedEars' Lahn wrote:

> bill wrote:
>> On 9/7/2012 2:07 PM, Tim Streater wrote:
>>> In article <1guuas2go7c0i$(dot)1aviei1ybpcod$(dot)dlg(at)40tude(dot)net>,
>>> nawfer <novalidsforspam(at)alt(dot)al> wrote:
>>>> Il Fri, 7 Sep 2012 13:48:29 +0000 (UTC), Salvatore ha scritto:
>>>> > On 2012-09-07, nawfer <novalidsforspam(at)alt(dot)al> wrote:
>>>> >> if have one of this date so
>>>> >>
>>>> >> Thu, 06/09/2012 - 23:50
>>>> >> Thursday, 6 September, 2012 - 23:50
>>>> >> Thu, 06/09/2012 - 23:50
>>>> >> 06/09/2012 - 23:50
>>>> >>
>>>> >> how can have this >> 2012-09-06T23:50:00
>>>> >>
>>>> >> and finally to have the seconds 1346968200
>>>> > > I'm not sure if you're asking how to *format* a date or how
>>>> > > to *parse* a date. If you want to format a date, given a
>>>> > > timestamp, use either the date() function or the strftime()
>>>> > > function. If you want to parse a date, given a string, use
>>>> > > either the strtotime() function or the strptime()
>>>> > > function.
>>>>
>>>> if have this string
>>>> "06/09/2012 - 23:50"
>>>
>>> Use strtotime () to convert the above into seconds.
>> then use date() to convert it back to the format you want.
>
> In this case, strptime() and strftime() should be used instead because, in
> contrast to strtotime() and date(), they observe the current locale (note
> the German month name above),

OK, bad example. It's not German here, for the weekday is in English. But
you see my point:

> and you get to choose the supported format with strptime(), so there are
> no ambiguities with parsing. […]
> That is, if, and only if, the hyphen is removed before; else it returns
> FALSE because that is not one of the formats supported by it. Tested
^^^^^
> with PHP 5.3.10-1 (cli) (built: Feb 3 2012 10:03:01).


PointedEars
--
> If you get a bunch of authors […] that state the same "best practices"
> in any programming language, then you can bet who is wrong or right...
Not with javascript. Nonsense propagates like wildfire in this field.
-- Richard Cornford, comp.lang.javascript, 2011-11-14
Re: how format one date [message #179113 is a reply to message #179059] Thu, 13 September 2012 14:29 Go to previous message
nawfer is currently offline  nawfer
Messages: 34
Registered: August 2011
Karma: 0
Member
Il Fri, 7 Sep 2012 15:39:36 +0000 (UTC), Salvatore ha scritto:

> On 2012-09-07, nawfer <novalidsforspam(at)alt(dot)al> wrote:
>> I have this error
>> Call to undefined function strptime()
>>
>> I use php 5.2.10
>
> Are you running PHP on Windows?

yes
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Converting eps to png
Next Topic: Never log deprecation warnings
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 22:21:48 GMT 2024

Total time taken to generate the page: 0.02469 seconds