Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #6981 > unrolled thread

how format one date

Started bynawfer <novalidsforspam@alt.al>
First post2012-09-07 15:28 +0200
Last post2012-09-08 00:22 +0200
Articles 12 — 6 participants

Back to article view | Back to comp.lang.php


Contents

  how format one date nawfer <novalidsforspam@alt.al> - 2012-09-07 15:28 +0200
    Re: how format one date Salvatore <sal@yojimbo.hack.invalid> - 2012-09-07 13:48 +0000
      Re: how format one date nawfer <novalidsforspam@alt.al> - 2012-09-07 16:56 +0200
        Re: how format one date Salvatore <sal@yojimbo.hack.invalid> - 2012-09-07 15:10 +0000
          Re: how format one date nawfer <novalidsforspam@alt.al> - 2012-09-07 17:20 +0200
            Re: how format one date Salvatore <sal@yojimbo.hack.invalid> - 2012-09-07 15:39 +0000
              Re: how format one date nawfer <novalidsforspam@alt.al> - 2012-09-13 16:29 +0200
            Re: how format one date Luuk <luuk@invalid.lan> - 2012-09-07 22:05 +0200
        Re: how format one date Tim Streater <timstreater@greenbee.net> - 2012-09-07 19:07 +0100
          Re: how format one date bill <william@TechServSys.com> - 2012-09-07 15:28 -0400
            Re: how format one date Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-08 00:19 +0200
              Re: how format one date Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-08 00:22 +0200

#6981 — how format one date

Fromnawfer <novalidsforspam@alt.al>
Date2012-09-07 15:28 +0200
Subjecthow format one date
Message-ID<167rucpmv69q.h70u289ic3i6$.dlg@40tude.net>
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

[toc] | [next] | [standalone]


#6982

FromSalvatore <sal@yojimbo.hack.invalid>
Date2012-09-07 13:48 +0000
Message-ID<k2ctvd$3191$1@yojimbo.hack>
In reply to#6981
On 2012-09-07, nawfer <novalidsforspam@alt.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++

[toc] | [prev] | [next] | [standalone]


#6983

Fromnawfer <novalidsforspam@alt.al>
Date2012-09-07 16:56 +0200
Message-ID<1guuas2go7c0i$.1aviei1ybpcod$.dlg@40tude.net>
In reply to#6982
Il Fri, 7 Sep 2012 13:48:29 +0000 (UTC), Salvatore ha scritto:

> On 2012-09-07, nawfer <novalidsforspam@alt.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

[toc] | [prev] | [next] | [standalone]


#6984

FromSalvatore <sal@yojimbo.hack.invalid>
Date2012-09-07 15:10 +0000
Message-ID<k2d2pp$2o1$1@yojimbo.hack>
In reply to#6983
On 2012-09-07, nawfer <novalidsforspam@alt.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++

[toc] | [prev] | [next] | [standalone]


#6985

Fromnawfer <novalidsforspam@alt.al>
Date2012-09-07 17:20 +0200
Message-ID<1drz2gfko6zgp$.1c0rji6yfwubw$.dlg@40tude.net>
In reply to#6984
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

[toc] | [prev] | [next] | [standalone]


#6986

FromSalvatore <sal@yojimbo.hack.invalid>
Date2012-09-07 15:39 +0000
Message-ID<k2d4fo$3qr$1@yojimbo.hack>
In reply to#6985
On 2012-09-07, nawfer <novalidsforspam@alt.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++

[toc] | [prev] | [next] | [standalone]


#7041

Fromnawfer <novalidsforspam@alt.al>
Date2012-09-13 16:29 +0200
Message-ID<wmltkm6n8d6c$.gbj0yjnfnavc.dlg@40tude.net>
In reply to#6986
Il Fri, 7 Sep 2012 15:39:36 +0000 (UTC), Salvatore ha scritto:

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

yes

[toc] | [prev] | [next] | [standalone]


#6989

FromLuuk <luuk@invalid.lan>
Date2012-09-07 22:05 +0200
Message-ID<0m0qh9-c47.ln1@luuk.invalid.lan>
In reply to#6985
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...... ;)

[toc] | [prev] | [next] | [standalone]


#6987

FromTim Streater <timstreater@greenbee.net>
Date2012-09-07 19:07 +0100
Message-ID<timstreater-7DBA59.19074607092012@news.individual.net>
In reply to#6983
In article <1guuas2go7c0i$.1aviei1ybpcod$.dlg@40tude.net>,
 nawfer <novalidsforspam@alt.al> wrote:

> Il Fri, 7 Sep 2012 13:48:29 +0000 (UTC), Salvatore ha scritto:
> 
> > On 2012-09-07, nawfer <novalidsforspam@alt.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

[toc] | [prev] | [next] | [standalone]


#6988

Frombill <william@TechServSys.com>
Date2012-09-07 15:28 -0400
Message-ID<k2dhtd$t7k$1@speranza.aioe.org>
In reply to#6987
On 9/7/2012 2:07 PM, Tim Streater wrote:
> In article <1guuas2go7c0i$.1aviei1ybpcod$.dlg@40tude.net>,
> nawfer <novalidsforspam@alt.al> wrote:
>
>> Il Fri, 7 Sep 2012 13:48:29 +0000 (UTC), Salvatore ha scritto:
>>
>> > On 2012-09-07, nawfer <novalidsforspam@alt.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
>

[toc] | [prev] | [next] | [standalone]


#6990

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-09-08 00:19 +0200
Message-ID<1584824.OSQIn9VdOr@PointedEars.de>
In reply to#6988
bill wrote:

> On 9/7/2012 2:07 PM, Tim Streater wrote:
>> In article <1guuas2go7c0i$.1aviei1ybpcod$.dlg@40tude.net>,
>> nawfer <novalidsforspam@alt.al> wrote:
>>> Il Fri, 7 Sep 2012 13:48:29 +0000 (UTC), Salvatore ha scritto:
>>> > On 2012-09-07, nawfer <novalidsforspam@alt.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

[toc] | [prev] | [next] | [standalone]


#6991

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-09-08 00:22 +0200
Message-ID<3740232.YjNHZVqIbo@PointedEars.de>
In reply to#6990
Thomas 'PointedEars' Lahn wrote:

> bill wrote:
>> On 9/7/2012 2:07 PM, Tim Streater wrote:
>>> In article <1guuas2go7c0i$.1aviei1ybpcod$.dlg@40tude.net>,
>>> nawfer <novalidsforspam@alt.al> wrote:
>>>> Il Fri, 7 Sep 2012 13:48:29 +0000 (UTC), Salvatore ha scritto:
>>>> > On 2012-09-07, nawfer <novalidsforspam@alt.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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web