[PHP] DateTime wierdness

2012-03-29 Thread Martín Marqués
Can someone explain to me this weierdness I see when using the
DateTime module of PHP.

Here I send 14/14/2012 which is not a valid date, and I would expect
to recieve false, but instead, it looks like it wrapping to the next
year, as if 14 monthas are 1 year and 2 months. That isn't what's
supposed to happen, or is it?

$ echo ?php var_dump(DateTime::createFromFormat('j/n/Y',
'14/14/2012')); ? |php
object(DateTime)#1 (3) {
  [date]=
  string(19) 2013-02-14 13:20:22
  [timezone_type]=
  int(3)
  [timezone]=
  string(20) America/Buenos_Aires
}


-- 
Martín Marqués
select 'martin.marques' || '@' || 'gmail.com'
DBA, Programador, Administrador

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] DateTime wierdness

2012-03-29 Thread David OBrien
echo date(m-d-y,mktime(0, 0, 0, 14, 14, 2012));

this outputs 02-14-13 also so my guess is that it is being interpreted
the same as  12/14/2012 +2 months

echo date(m-d-y,mktime(0, 0, 0, 1, 45, 2012)); outputs
02-14-12

which is 1/1/12 +45 days



2012/3/29 Martín Marqués martin.marq...@gmail.com

 Can someone explain to me this weierdness I see when using the
 DateTime module of PHP.

 Here I send 14/14/2012 which is not a valid date, and I would expect
 to recieve false, but instead, it looks like it wrapping to the next
 year, as if 14 monthas are 1 year and 2 months. That isn't what's
 supposed to happen, or is it?

 $ echo ?php var_dump(DateTime::createFromFormat('j/n/Y',
 '14/14/2012')); ? |php
 object(DateTime)#1 (3) {
  [date]=
  string(19) 2013-02-14 13:20:22
  [timezone_type]=
  int(3)
  [timezone]=
  string(20) America/Buenos_Aires
 }


 --
 Martín Marqués
 select 'martin.marques' || '@' || 'gmail.com'
 DBA, Programador, Administrador

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] DateTime wierdness

2012-03-29 Thread Martín Marqués
OK. So what would be a good way to validate a date?

El día 29 de marzo de 2012 14:04, David OBrien dgobr...@gmail.com escribió:

 echo date(m-d-y,mktime(0, 0, 0, 14, 14, 2012));

 this outputs 02-14-13 also so my guess is that it is being interpreted the
 same as  12/14/2012 +2 months

 echo date(m-d-y,mktime(0, 0, 0, 1, 45, 2012)); outputs
 02-14-12

 which is 1/1/12 +45 days



 2012/3/29 Martín Marqués martin.marq...@gmail.com

 Can someone explain to me this weierdness I see when using the
 DateTime module of PHP.

 Here I send 14/14/2012 which is not a valid date, and I would expect
 to recieve false, but instead, it looks like it wrapping to the next
 year, as if 14 monthas are 1 year and 2 months. That isn't what's
 supposed to happen, or is it?

 $ echo ?php var_dump(DateTime::createFromFormat('j/n/Y',
 '14/14/2012')); ? |php
 object(DateTime)#1 (3) {
  [date]=
  string(19) 2013-02-14 13:20:22
  [timezone_type]=
  int(3)
  [timezone]=
  string(20) America/Buenos_Aires
 }


 --
 Martín Marqués
 select 'martin.marques' || '@' || 'gmail.com'
 DBA, Programador, Administrador

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php





-- 
Martín Marqués
select 'martin.marques' || '@' || 'gmail.com'
DBA, Programador, Administrador

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] DateTime wierdness

2012-03-29 Thread David OBrien
http://www.php.net/manual/en/function.checkdate.php

2012/3/29 Martín Marqués martin.marq...@gmail.com

 OK. So what would be a good way to validate a date?

 El día 29 de marzo de 2012 14:04, David OBrien dgobr...@gmail.com
 escribió:
 
  echo date(m-d-y,mktime(0, 0, 0, 14, 14, 2012));
 
  this outputs 02-14-13 also so my guess is that it is being interpreted
 the
  same as  12/14/2012 +2 months
 
  echo date(m-d-y,mktime(0, 0, 0, 1, 45, 2012)); outputs
  02-14-12
 
  which is 1/1/12 +45 days
 
 
 
  2012/3/29 Martín Marqués martin.marq...@gmail.com
 
  Can someone explain to me this weierdness I see when using the
  DateTime module of PHP.
 
  Here I send 14/14/2012 which is not a valid date, and I would expect
  to recieve false, but instead, it looks like it wrapping to the next
  year, as if 14 monthas are 1 year and 2 months. That isn't what's
  supposed to happen, or is it?
 
  $ echo ?php var_dump(DateTime::createFromFormat('j/n/Y',
  '14/14/2012')); ? |php
  object(DateTime)#1 (3) {
   [date]=
   string(19) 2013-02-14 13:20:22
   [timezone_type]=
   int(3)
   [timezone]=
   string(20) America/Buenos_Aires
  }
 
 
  --
  Martín Marqués
  select 'martin.marques' || '@' || 'gmail.com'
  DBA, Programador, Administrador
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 



 --
 Martín Marqués
 select 'martin.marques' || '@' || 'gmail.com'
 DBA, Programador, Administrador



Re: [PHP] DateTime wierdness

2012-03-29 Thread David OBrien
actually this would work well ... compare what they send with the output of
the formatdate

function checkDateTime($data) {
if (date('Y-m-d H:i:s', strtotime($data)) == $data) {
return true;
} else {
return false;
}
}

2012/3/29 David OBrien dgobr...@gmail.com

 http://www.php.net/manual/en/function.checkdate.php


 2012/3/29 Martín Marqués martin.marq...@gmail.com

 OK. So what would be a good way to validate a date?

 El día 29 de marzo de 2012 14:04, David OBrien dgobr...@gmail.com
 escribió:
 
  echo date(m-d-y,mktime(0, 0, 0, 14, 14, 2012));
 
  this outputs 02-14-13 also so my guess is that it is being
 interpreted the
  same as  12/14/2012 +2 months
 
  echo date(m-d-y,mktime(0, 0, 0, 1, 45, 2012)); outputs
  02-14-12
 
  which is 1/1/12 +45 days
 
 
 
  2012/3/29 Martín Marqués martin.marq...@gmail.com
 
  Can someone explain to me this weierdness I see when using the
  DateTime module of PHP.
 
  Here I send 14/14/2012 which is not a valid date, and I would expect
  to recieve false, but instead, it looks like it wrapping to the next
  year, as if 14 monthas are 1 year and 2 months. That isn't what's
  supposed to happen, or is it?
 
  $ echo ?php var_dump(DateTime::createFromFormat('j/n/Y',
  '14/14/2012')); ? |php
  object(DateTime)#1 (3) {
   [date]=
   string(19) 2013-02-14 13:20:22
   [timezone_type]=
   int(3)
   [timezone]=
   string(20) America/Buenos_Aires
  }
 
 
  --
  Martín Marqués
  select 'martin.marques' || '@' || 'gmail.com'
  DBA, Programador, Administrador
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 



 --
 Martín Marqués
 select 'martin.marques' || '@' || 'gmail.com'
 DBA, Programador, Administrador





Re: [PHP] DateTime wierdness

2012-03-29 Thread Martín Marqués
El día 29 de marzo de 2012 14:14, David OBrien dgobr...@gmail.com escribió:
 actually this would work well ... compare what they send with the output of
 the formatdate

 function checkDateTime($data) {
     if (date('Y-m-d H:i:s', strtotime($data)) == $data) {
         return true;
     } else {
         return false;

     }
 }

Well, I did somethin similar...

$arDate = explode(/, $nacimiento);
if(!checkdate($arDate[1], $arDate[0], $arDate[2]))
  $nacimiento = '';

Just need to set the variable $nacimiento to the empty string if it's
not a valid date.

Thanks anyway,


-- 
Martín Marqués
select 'martin.marques' || '@' || 'gmail.com'
DBA, Programador, Administrador

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] DateTime wierdness

2012-03-29 Thread tamouse mailing lists
2012/3/29 Martín Marqués martin.marq...@gmail.com:
 El día 29 de marzo de 2012 14:14, David OBrien dgobr...@gmail.com escribió:
 actually this would work well ... compare what they send with the output of
 the formatdate

 function checkDateTime($data) {
     if (date('Y-m-d H:i:s', strtotime($data)) == $data) {
         return true;
     } else {
         return false;

     }
 }

 Well, I did somethin similar...

    $arDate = explode(/, $nacimiento);
    if(!checkdate($arDate[1], $arDate[0], $arDate[2]))
      $nacimiento = '';

 Just need to set the variable $nacimiento to the empty string if it's
 not a valid date.

 Thanks anyway,


 --
 Martín Marqués
 select 'martin.marques' || '@' || 'gmail.com'
 DBA, Programador, Administrador

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


I don't know how it came to be, but a lot of people rely on this
behaviour. It does make sense if you squint at it a bit -- trust that
the programmer meant what they said and deliver something useful,
leave error checking up to the programmer. I'm a bit ambivalent about
it, personally, but the way it's implemented does seem more flexible.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] DateTime using DateTimeZone Timestamp problem

2011-04-05 Thread Simon J Welsh
On 5/04/2011, at 3:35 AM, Ian wrote:

 Hi,
 
 I have a problem using the php built in classes DateTime and DateTimeZone.
 
 The idea behind the following code is to return the timestamp for the
 current time in Singapore (or other places).  What it actually returns
 is the timestamp for the local system. Other formatted dates appear to
 return correctly, which is why I am puzzled.
 
 I am using the latest php 5.3.6 compiled from source on a OpenVZ CentOS
 container. All packages are up to date.
 
 Am I doing something wrong or is this a bug?
 
 I can workaround this problem my parsing the correctly formatted date
 using strtotime() but I would like to know what's going on.
 
 
 
 This is the output of the script:
 
   Current time in Asia/Singapore is 2011-04-04 23:32:36
   Timestamp for Asia/Singapore is 1301931156
   Date created from previous timestamp is 2011-04-04 16:32:36
 
 The code is :
 
 ?php
 
 $timezone=Asia/Singapore;
 
 # Create Timezone object
 $remote_timezone  = new DateTimeZone($timezone);
 
 # Create datetime object
 $remote_time  = new DateTime(now , $remote_timezone);
 
 # Print the date
 print Current time in {$timezone} ;
 print is {$remote_time-format(Y-m-d H:i:s)}br/;
 
 # Print the timestamp
 print Timestamp for {$timezone} ;
 print is {$remote_time-format(U)}br /;
 
 # Get the timestamp and create a date from it
 $timestamp = (int)$remote_time-format(U);
 
 # Show the formatted date created from timestamp
 print Date created from previous timestamp is ;
 print date(Y-m-d H:i:s,$timestamp).br/;
 
 ?

May I suggest including the timezone in your date format (O or e)? It may show 
the two date strings to be equivalent.

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] DateTime using DateTimeZone Timestamp problem

2011-04-05 Thread Richard Quadling
On 4 April 2011 16:35, Ian php_l...@fishnet.co.uk wrote:
 Hi,

 I have a problem using the php built in classes DateTime and DateTimeZone.

 The idea behind the following code is to return the timestamp for the
 current time in Singapore (or other places).  What it actually returns
 is the timestamp for the local system. Other formatted dates appear to
 return correctly, which is why I am puzzled.

 I am using the latest php 5.3.6 compiled from source on a OpenVZ CentOS
 container. All packages are up to date.

 Am I doing something wrong or is this a bug?

 I can workaround this problem my parsing the correctly formatted date
 using strtotime() but I would like to know what's going on.



 This is the output of the script:

        Current time in Asia/Singapore is 2011-04-04 23:32:36
        Timestamp for Asia/Singapore is 1301931156
        Date created from previous timestamp is 2011-04-04 16:32:36

 The code is :

 ?php

 $timezone=Asia/Singapore;

 # Create Timezone object
 $remote_timezone        = new DateTimeZone($timezone);

 # Create datetime object
 $remote_time            = new DateTime(now , $remote_timezone);

 # Print the date
 print Current time in {$timezone} ;
 print is {$remote_time-format(Y-m-d H:i:s)}br/;

 # Print the timestamp
 print Timestamp for {$timezone} ;
 print is {$remote_time-format(U)}br /;

 # Get the timestamp and create a date from it
 $timestamp = (int)$remote_time-format(U);

 # Show the formatted date created from timestamp
 print Date created from previous timestamp is ;
 print date(Y-m-d H:i:s,$timestamp).br/;

 ?

Timestamps (the integer value) do not hold the timezone data.
Internally, the value represents a number of milliseconds from a point
in time.

So saying timestamp for Asia/Singapore isn't right. It is just Timestamp.

The following script (http://pastebin.com/0MQAaYUq) may show you in a
more concrete way ...

?php
$a_Times = array(
'now',
'2011-03-27 00:59:59',
'2011-03-27 02:00:00',
);

// Create Timezone objects
$a_Timezones = array(
'Singapore' = new DateTimeZone('Asia/Singapore'),
'NewYork  ' = new DateTimeZone('America/New_York'),
'London   ' = new DateTimeZone('Europe/London'),
'UTC  ' = new DateTimeZone('UTC'),
);

foreach($a_Times as $s_Time) {
echo 'Time : ', $s_Time, PHP_EOL;

// Create datetime objects
$a_DateTimes = array();
foreach($a_Timezones as $s_Timezone = $tz_Timezone) {
$a_DateTimes[$s_Timezone] = new DateTime($s_Time , 
$tz_Timezone);
}

// Print the date
foreach($a_DateTimes as $s_Timezone = $dt_DateTime) {
echo
'Current time in ', $s_Timezone, ' : ', 
$dt_DateTime-format(DateTime::RSS),
'   Offset : ', str_pad($dt_DateTime-getOffset(), 6, ' 
', STR_PAD_LEFT),
'   Timestamp : ', ($i_Timestamp = 
$dt_DateTime-getTimestamp()),
'   Local : ', date(DateTime::RSS, $i_Timestamp), 
PHP_EOL;
}
echo PHP_EOL;
}
?

outputs (http://pastebin.com/mETSbR7h) ...

Time : now
Current time in Singapore : Tue, 05 Apr 2011 17:56:32 +0800   Offset :
 28800   Timestamp : 1301997392   Local : Tue, 05 Apr 2011 10:56:32
+0100
Current time in NewYork   : Tue, 05 Apr 2011 05:56:32 -0400   Offset :
-14400   Timestamp : 1301997392   Local : Tue, 05 Apr 2011 10:56:32
+0100
Current time in London: Tue, 05 Apr 2011 10:56:32 +0100   Offset :
  3600   Timestamp : 1301997392   Local : Tue, 05 Apr 2011 10:56:32
+0100
Current time in UTC   : Tue, 05 Apr 2011 09:56:32 +   Offset :
 0   Timestamp : 1301997392   Local : Tue, 05 Apr 2011 10:56:32
+0100

Time : 2011-03-27 00:59:59
Current time in Singapore : Sun, 27 Mar 2011 00:59:59 +0800   Offset :
 28800   Timestamp : 1301158799   Local : Sat, 26 Mar 2011 16:59:59
+
Current time in NewYork   : Sun, 27 Mar 2011 00:59:59 -0400   Offset :
-14400   Timestamp : 1301201999   Local : Sun, 27 Mar 2011 05:59:59
+0100
Current time in London: Sun, 27 Mar 2011 00:59:59 +   Offset :
 0   Timestamp : 1301187599   Local : Sun, 27 Mar 2011 00:59:59
+
Current time in UTC   : Sun, 27 Mar 2011 00:59:59 +   Offset :
 0   Timestamp : 1301187599   Local : Sun, 27 Mar 2011 00:59:59
+

Time : 2011-03-27 02:00:00
Current time in Singapore : Sun, 27 Mar 2011 02:00:00 +0800   Offset :
 28800   Timestamp : 1301162400   Local : Sat, 26 Mar 2011 18:00:00
+
Current time in NewYork   : Sun, 27 Mar 2011 02:00:00 -0400   Offset :
-14400   Timestamp : 1301205600   Local : Sun, 27 Mar 2011 07:00:00
+0100
Current time in London: Sun, 27 Mar 2011 02:00:00 +0100   Offset :
  3600   Timestamp : 1301187600   Local : Sun, 27 Mar 2011 02:00:00
+0100
Current time in UTC   : Sun, 27 Mar 2011 02:00:00 +   Offset :
 0   Timestamp : 1301191200   Local : Sun, 27 Mar 2011 03:00:00
+0100


Getting the the timestamp for a DateTime object 

[PHP] DateTime using DateTimeZone Timestamp problem

2011-04-04 Thread Ian
Hi,

I have a problem using the php built in classes DateTime and DateTimeZone.

The idea behind the following code is to return the timestamp for the
current time in Singapore (or other places).  What it actually returns
is the timestamp for the local system. Other formatted dates appear to
return correctly, which is why I am puzzled.

I am using the latest php 5.3.6 compiled from source on a OpenVZ CentOS
container. All packages are up to date.

Am I doing something wrong or is this a bug?

I can workaround this problem my parsing the correctly formatted date
using strtotime() but I would like to know what's going on.



This is the output of the script:

Current time in Asia/Singapore is 2011-04-04 23:32:36
Timestamp for Asia/Singapore is 1301931156
Date created from previous timestamp is 2011-04-04 16:32:36

The code is :

?php

$timezone=Asia/Singapore;

# Create Timezone object
$remote_timezone= new DateTimeZone($timezone);

# Create datetime object
$remote_time= new DateTime(now , $remote_timezone);

# Print the date
print Current time in {$timezone} ;
print is {$remote_time-format(Y-m-d H:i:s)}br/;

# Print the timestamp
print Timestamp for {$timezone} ;
print is {$remote_time-format(U)}br /;

# Get the timestamp and create a date from it
$timestamp = (int)$remote_time-format(U);

# Show the formatted date created from timestamp
print Date created from previous timestamp is ;
print date(Y-m-d H:i:s,$timestamp).br/;

?



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] DateTime using DateTimeZone Timestamp problem

2011-04-04 Thread Ashley Sheridan
On Mon, 2011-04-04 at 16:35 +0100, Ian wrote:

 Hi,
 
 I have a problem using the php built in classes DateTime and DateTimeZone.
 
 The idea behind the following code is to return the timestamp for the
 current time in Singapore (or other places).  What it actually returns
 is the timestamp for the local system. Other formatted dates appear to
 return correctly, which is why I am puzzled.
 
 I am using the latest php 5.3.6 compiled from source on a OpenVZ CentOS
 container. All packages are up to date.
 
 Am I doing something wrong or is this a bug?
 
 I can workaround this problem my parsing the correctly formatted date
 using strtotime() but I would like to know what's going on.
 
 
 
 This is the output of the script:
 
   Current time in Asia/Singapore is 2011-04-04 23:32:36
   Timestamp for Asia/Singapore is 1301931156
   Date created from previous timestamp is 2011-04-04 16:32:36
 
 The code is :
 
 ?php
 
 $timezone=Asia/Singapore;
 
 # Create Timezone object
 $remote_timezone  = new DateTimeZone($timezone);
 
 # Create datetime object
 $remote_time  = new DateTime(now , $remote_timezone);
 
 # Print the date
 print Current time in {$timezone} ;
 print is {$remote_time-format(Y-m-d H:i:s)}br/;
 
 # Print the timestamp
 print Timestamp for {$timezone} ;
 print is {$remote_time-format(U)}br /;
 
 # Get the timestamp and create a date from it
 $timestamp = (int)$remote_time-format(U);
 
 # Show the formatted date created from timestamp
 print Date created from previous timestamp is ;
 print date(Y-m-d H:i:s,$timestamp).br/;
 
 ?
 
 
 


What do you mean it only returns the timestamp for the local system? Did
you want PHP to know what time the visitors are on? PHP won't know about
that, all you can do is set the timezone for the script based on some
information you're receiving from a clients machine, otherwise PHP won't
know, because it's only run on the server and doesn't know about the
client machines? Is this what you're trying to do, or did I
misunderstand?

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] DateTime... What else ?

2008-04-17 Thread Stut

On 17 Apr 2008, at 10:05, David BERCOT wrote:

I've got a problem with DateTime. I have a short code which gives an
error :

CODE
$date = new DateTime(date(d/m/Y));
$date-modify(-1 month);
$mois_en_cours1 = $date-format(Y-m);
$date-modify(-1 month);
$mois_en_cours2 = $date-format(Y-m);
$date-modify(-1 month);
$mois_en_cours3 = $date-format(Y-m);
/CODE

ERROR
bFatal error/b:  Class 'DateTime' not found in
b/var/www2/dacg_visio/index.html/b on line b244/bbr /
/ERROR

If I look at the documentation :
http://fr3.php.net/manual/fr/function.date-modify.php
it seems to work if PHP version is above 5.1.0 (I am in 5.1.6 !).

Do you have any idea about this error (Debian/Apache2) ?
Do you have another way to obtain $mois_en_cours1, 2, 3 without
DateTime ?


Pre-5.2 you need to explicitly say you want the DateTime class. See  
the note on this page: http://fr3.php.net/manual/fr/datetime.installation.php


Also note that it's experimental at the moment and therefore not  
recommended for production usage.


-Stut

--
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] DateTime... What else ?

2008-04-17 Thread Simon Welsh


On 17/04/2008, at 9:05, David BERCOT wrote:

Hi,

I've got a problem with DateTime. I have a short code which gives an
error :

CODE
$date = new DateTime(date(d/m/Y));
$date-modify(-1 month);
$mois_en_cours1 = $date-format(Y-m);
$date-modify(-1 month);
$mois_en_cours2 = $date-format(Y-m);
$date-modify(-1 month);
$mois_en_cours3 = $date-format(Y-m);
/CODE

ERROR
bFatal error/b:  Class 'DateTime' not found in
b/var/www2/dacg_visio/index.html/b on line b244/bbr /
/ERROR

If I look at the documentation :
http://fr3.php.net/manual/fr/function.date-modify.php
it seems to work if PHP version is above 5.1.0 (I am in 5.1.6 !).

Do you have any idea about this error (Debian/Apache2) ?
Do you have another way to obtain $mois_en_cours1, 2, 3 without
DateTime ?

Thank you very much.

David.


--  
PHP General Mailing List (http://www.php.net/)

To unsubscribe, visit: http://www.php.net/unsub.php




?php
$mois_en_cours1 = date('Y-m', strtotime('-1 month'));
$mois_en_cours2 = date('Y-m', strtotime('-2 month'));
$mois_en_cours3 = date('Y-m', strtotime('-3 month'));
?

---
Simon Welsh
Admin of http://simon.geek.nz/

Windows is a joke operating system. Hell, it's not even an operating  
system. NT is Not Tough enough for me either. 95 is how may times it  
will crash an hour.


http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] DateTime... What else ?

2008-04-17 Thread David BERCOT
Hi,

I've got a problem with DateTime. I have a short code which gives an
error :

CODE
$date = new DateTime(date(d/m/Y));
$date-modify(-1 month);
$mois_en_cours1 = $date-format(Y-m);
$date-modify(-1 month);
$mois_en_cours2 = $date-format(Y-m);
$date-modify(-1 month);
$mois_en_cours3 = $date-format(Y-m);
/CODE

ERROR
bFatal error/b:  Class 'DateTime' not found in
b/var/www2/dacg_visio/index.html/b on line b244/bbr /
/ERROR

If I look at the documentation :
http://fr3.php.net/manual/fr/function.date-modify.php
it seems to work if PHP version is above 5.1.0 (I am in 5.1.6 !).

Do you have any idea about this error (Debian/Apache2) ?
Do you have another way to obtain $mois_en_cours1, 2, 3 without
DateTime ?

Thank you very much.

David.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] DateTime... What else ?

2008-04-17 Thread David BERCOT
Hi again,

Le Thu, 17 Apr 2008 21:10:44 +1200,
Simon Welsh [EMAIL PROTECTED] a écrit :
 On 17/04/2008, at 9:05, David BERCOT wrote:
  Hi,
 
  I've got a problem with DateTime. I have a short code which gives an
  error :
 
  CODE
  $date = new DateTime(date(d/m/Y));
  $date-modify(-1 month);
  $mois_en_cours1 = $date-format(Y-m);
  $date-modify(-1 month);
  $mois_en_cours2 = $date-format(Y-m);
  $date-modify(-1 month);
  $mois_en_cours3 = $date-format(Y-m);
  /CODE
 
  ERROR
  bFatal error/b:  Class 'DateTime' not found in
  b/var/www2/dacg_visio/index.html/b on line b244/bbr /
  /ERROR
 
  If I look at the documentation :
  http://fr3.php.net/manual/fr/function.date-modify.php
  it seems to work if PHP version is above 5.1.0 (I am in 5.1.6 !).
 
  Do you have any idea about this error (Debian/Apache2) ?
  Do you have another way to obtain $mois_en_cours1, 2, 3 without
  DateTime ?
 
  Thank you very much.
 
  David.
 
 ?php
 $mois_en_cours1 = date('Y-m', strtotime('-1 month'));
 $mois_en_cours2 = date('Y-m', strtotime('-2 month'));
 $mois_en_cours3 = date('Y-m', strtotime('-3 month'));
 ?

Great ;-)

Thank you very much !

David.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] DateTime... What else ?

2008-04-17 Thread David BERCOT
Le Thu, 17 Apr 2008 10:19:10 +0100,
Stut [EMAIL PROTECTED] a écrit :
 On 17 Apr 2008, at 10:05, David BERCOT wrote:
  I've got a problem with DateTime. I have a short code which gives an
  error :
 
  CODE
  $date = new DateTime(date(d/m/Y));
  $date-modify(-1 month);
  $mois_en_cours1 = $date-format(Y-m);
  $date-modify(-1 month);
  $mois_en_cours2 = $date-format(Y-m);
  $date-modify(-1 month);
  $mois_en_cours3 = $date-format(Y-m);
  /CODE
 
  ERROR
  bFatal error/b:  Class 'DateTime' not found in
  b/var/www2/dacg_visio/index.html/b on line b244/bbr /
  /ERROR
 
  If I look at the documentation :
  http://fr3.php.net/manual/fr/function.date-modify.php
  it seems to work if PHP version is above 5.1.0 (I am in 5.1.6 !).
 
  Do you have any idea about this error (Debian/Apache2) ?
  Do you have another way to obtain $mois_en_cours1, 2, 3 without
  DateTime ?
 
 Pre-5.2 you need to explicitly say you want the DateTime class. See  
 the note on this page:
 http://fr3.php.net/manual/fr/datetime.installation.php
 
 Also note that it's experimental at the moment and therefore not  
 recommended for production usage.

OK. So, my error is normal !!!

Thank you very much.

David.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] DATETIME or UNIX TIMESTAMPS?

2006-10-26 Thread Marcelo de Moraes Serpa

Hello list,

I've always used Unix Timestamps until now, but lately I've reading about
MySQL's datetime datatype and its benefits (dates before 1970, after 2030,
SQL functions to deal with them, etc). However, I don't see much support for
them in the PHP API. I'm also a Flash programmer and the Flash 8 API Date
datatype also only understands unix timestamps. Taking this into account,
I'm not really sure if it really worths it to move to the DATETIME
datatype. What would you do? Any advice would be much appreciated!

Marcelo.


Re: [PHP] DATETIME or UNIX TIMESTAMPS?

2006-10-26 Thread Larry Garfield
On Thursday 26 October 2006 15:36, Marcelo de Moraes Serpa wrote:
 Hello list,

 I've always used Unix Timestamps until now, but lately I've reading about
 MySQL's datetime datatype and its benefits (dates before 1970, after 2030,
 SQL functions to deal with them, etc). However, I don't see much support
 for them in the PHP API. I'm also a Flash programmer and the Flash 8 API
 Date datatype also only understands unix timestamps. Taking this into
 account, I'm not really sure if it really worths it to move to the
 DATETIME datatype. What would you do? Any advice would be much appreciated!

 Marcelo.

I tend to stick to unix timestamps as well, because date formats are 
completely unstandard between different SQL databases.  MySQL's date futzing 
functions are nice, but they're different than Postgres', which are different 
than Oracle's, etc.  

Generally, most of the the math I need to do I can do in PHP either before or 
after grabbing the timestamp.  

I am sure there is a counter point, but this for what I do I just stick to 
timestamps. :-)

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it.  -- Thomas 
Jefferson

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] datetime formatting problem

2004-05-28 Thread Matt Newell

hi all -

this is probably straight forward, but i'm learning and would appreciate
any insight.

i'm using the datetime type in mysql and have been able to successsfully
pull the data records's date, but it's failing out and giving me the
current time [as in what it says on my system's clock]

basically i'm just spitting out all the rows to an html table and would
like to have the date AND time formatted as is in the date(...) function
at the top of the code demo. 

thanks!
matt

/ begin code demo


function formatDate($val)
{
$arr = explode(-, $val);
return date(M d, Y g:i A, mktime(0,0,0, $arr[1], $arr[2], $arr[0]));
}


// open database connection
$connection = mysql_connect($host, $user, $pass) or die (Unable to
connect!);

// select database
mysql_select_db($db) or die (Unable to select database!);

// generate and execute query
$query = SELECT * FROM outdoor ORDER BY id ASC;
$result = mysql_query($query) or die (Error in query: $query.  .
mysql_error());


// if records present
if (mysql_num_rows($result)  0)
{
// iterate through resultset
// print title with links to edit and delete scripts
while($row = mysql_fetch_object($result))
{
?
tr
td? echo $row-id; ?/td
td? echo $row-name; ?/td
tda href=mailto:? echo $row-email; ?? echo
$row-email; ?/a/td
td? echo $row-zip ?/td
td? echo formatDate($row-date); ?/td
td? echo $row-club_member ?/td   
td? echo $row-driver ?/td
!-- tdfont size=-1? echo $row-active ?/font/td --

tdcentera href=edit.php?id=? echo $row-id; ?img
src=notepad.gif alt= width=16 height=16 border=0/a nbsp;
a href=delete.php?id=? echo $row-id; ?img src=trashcan.gif
alt= width=16 height=16 border=0/a/center/td
/tr
?
}
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] datetime formatting problem

2004-05-28 Thread Daniel Clark
Isn't date a reserved word?

 hi all -

 this is probably straight forward, but i'm learning and would appreciate
 any insight.

 i'm using the datetime type in mysql and have been able to successsfully
 pull the data records's date, but it's failing out and giving me the
 current time [as in what it says on my system's clock]

 basically i'm just spitting out all the rows to an html table and would
 like to have the date AND time formatted as is in the date(...) function
 at the top of the code demo.

 thanks!
 matt

 / begin code demo


 function formatDate($val)
 {
 $arr = explode(-, $val);
 return date(M d, Y g:i A, mktime(0,0,0, $arr[1], $arr[2], $arr[0]));
 }


 // open database connection
 $connection = mysql_connect($host, $user, $pass) or die (Unable to
 connect!);

 // select database
 mysql_select_db($db) or die (Unable to select database!);

 // generate and execute query
 $query = SELECT * FROM outdoor ORDER BY id ASC;
 $result = mysql_query($query) or die (Error in query: $query.  .
 mysql_error());


 // if records present
 if (mysql_num_rows($result)  0)
 {
   // iterate through resultset
   // print title with links to edit and delete scripts
   while($row = mysql_fetch_object($result))
   {
   ?
   tr
   td? echo $row-id; ?/td
   td? echo $row-name; ?/td
   tda href=mailto:? echo $row-email; ?? echo
 $row-email; ?/a/td
   td? echo $row-zip ?/td
   td? echo formatDate($row-date); ?/td
   td? echo $row-club_member ?/td
   td? echo $row-driver ?/td
   !-- tdfont size=-1? echo $row-active ?/font/td --

   tdcentera href=edit.php?id=? echo $row-id; ?img
 src=notepad.gif alt= width=16 height=16 border=0/a  
 a href=delete.php?id=? echo $row-id; ?img src=trashcan.gif
 alt= width=16 height=16 border=0/a/center/td
   /tr
   ?
   }
 }

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] datetime formatting problem

2004-05-28 Thread Torsten Roehr
Daniel Clark [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Isn't date a reserved word?

date and dateTime are not reserved in MySQL and can be used as column names.


  hi all -
 
  this is probably straight forward, but i'm learning and would appreciate
  any insight.
 
  i'm using the datetime type in mysql and have been able to successsfully
  pull the data records's date, but it's failing out and giving me the
  current time [as in what it says on my system's clock]
 
  basically i'm just spitting out all the rows to an html table and would
  like to have the date AND time formatted as is in the date(...) function
  at the top of the code demo.
 
  thanks!
  matt
 
  / begin code demo
 
 
  function formatDate($val)
  {
  $arr = explode(-, $val);
  return date(M d, Y g:i A, mktime(0,0,0, $arr[1], $arr[2], $arr[0]));
  }

Hi Matt,

try this:

function formatDate($val) {
$timestamp = strtotime($val);
return date('M d, Y g:i A', $timestamp);
}

Regards, Torsten Roehr

 
 
  // open database connection
  $connection = mysql_connect($host, $user, $pass) or die (Unable to
  connect!);
 
  // select database
  mysql_select_db($db) or die (Unable to select database!);
 
  // generate and execute query
  $query = SELECT * FROM outdoor ORDER BY id ASC;
  $result = mysql_query($query) or die (Error in query: $query.  .
  mysql_error());
 
 
  // if records present
  if (mysql_num_rows($result)  0)
  {
  // iterate through resultset
  // print title with links to edit and delete scripts
  while($row = mysql_fetch_object($result))
  {
  ?
  tr
  td? echo $row-id; ?/td
  td? echo $row-name; ?/td
  tda href=mailto:? echo $row-email; ?? echo
  $row-email; ?/a/td
  td? echo $row-zip ?/td
  td? echo formatDate($row-date); ?/td
  td? echo $row-club_member ?/td
  td? echo $row-driver ?/td
  !-- tdfont size=-1? echo $row-active ?/font/td --
 
   tdcentera href=edit.php?id=? echo $row-id; ?img
  src=notepad.gif alt= width=16 height=16 border=0/a
  a href=delete.php?id=? echo $row-id; ?img src=trashcan.gif
  alt= width=16 height=16 border=0/a/center/td
  /tr
  ?
  }
  }
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] datetime formatting problem

2004-05-28 Thread Jordan S. Jones
[snip /]
Hi Matt,
try this:
function formatDate($val) {
   $timestamp = strtotime($val);
   return date('M d, Y g:i A', $timestamp);
}
 

strtotime possibly will not work if your date is  01/01/1970.
[snip /]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] datetime formatting problem

2004-05-28 Thread Matt Newell

thanks a bunch torsten. it worked like a charm and i'm off to read up
some more on strtotime.

best,
m.

-Original Message-
From: Torsten Roehr [mailto:[EMAIL PROTECTED] 
Sent: Friday, May 28, 2004 2:07 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] datetime formatting problem

Daniel Clark [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Isn't date a reserved word?

date and dateTime are not reserved in MySQL and can be used as column
names.


  hi all -
 
  this is probably straight forward, but i'm learning and would 
  appreciate any insight.
 
  i'm using the datetime type in mysql and have been able to 
  successsfully pull the data records's date, but it's failing out and

  giving me the current time [as in what it says on my system's clock]
 
  basically i'm just spitting out all the rows to an html table and 
  would like to have the date AND time formatted as is in the 
  date(...) function at the top of the code demo.
 
  thanks!
  matt
 
  / begin code demo
 
 
  function formatDate($val)
  {
  $arr = explode(-, $val);
  return date(M d, Y g:i A, mktime(0,0,0, $arr[1], $arr[2], 
  $arr[0])); }

Hi Matt,

try this:

function formatDate($val) {
$timestamp = strtotime($val);
return date('M d, Y g:i A', $timestamp); }

Regards, Torsten Roehr

 
 
  // open database connection
  $connection = mysql_connect($host, $user, $pass) or die (Unable to 
  connect!);
 
  // select database
  mysql_select_db($db) or die (Unable to select database!);
 
  // generate and execute query
  $query = SELECT * FROM outdoor ORDER BY id ASC; $result = 
  mysql_query($query) or die (Error in query: $query.  .
  mysql_error());
 
 
  // if records present
  if (mysql_num_rows($result)  0)
  {
  // iterate through resultset
  // print title with links to edit and delete scripts while($row = 
  mysql_fetch_object($result)) { ? tr td? echo $row-id; ?/td

  td? echo $row-name; ?/td tda href=mailto:? echo 
  $row-email; ?? echo $row-email; ?/a/td td? echo 
  $row-zip ?/td td? echo formatDate($row-date); ?/td td?

  echo $row-club_member ?/td td? echo $row-driver ?/td
  !-- tdfont size=-1? echo $row-active ?/font/td --
 
   tdcentera href=edit.php?id=? echo $row-id; ?img 
  src=notepad.gif alt= width=16 height=16 border=0/a a 
  href=delete.php?id=? echo $row-id; ?img src=trashcan.gif
  alt= width=16 height=16 border=0/a/center/td /tr ?
  }
  }
 
  --
  PHP General Mailing List (http://www.php.net/) To unsubscribe, 
  visit: http://www.php.net/unsub.php
 
 

--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] datetime formatting problem

2004-05-28 Thread Matt Newell

appreciate the headsup, but all times will be from when record is
inserted which will not be possible before today.

thanks,
m. 

-Original Message-
From: Jordan S. Jones [mailto:[EMAIL PROTECTED] 
Sent: Friday, May 28, 2004 2:20 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] datetime formatting problem


[snip /]

Hi Matt,

try this:

function formatDate($val) {
$timestamp = strtotime($val);
return date('M d, Y g:i A', $timestamp); }
  

strtotime possibly will not work if your date is  01/01/1970.

[snip /]

--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] datetime formatting problem

2004-05-28 Thread Stephen Lake
Try strftime
it allows you to take a timestamp created by time() and format it as
required.
heres the man page for it:
http://www.php.net/manual/en/function.strftime.php

Matt Newell [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

thanks a bunch torsten. it worked like a charm and i'm off to read up
some more on strtotime.

best,
m.

-Original Message-
From: Torsten Roehr [mailto:[EMAIL PROTECTED]
Sent: Friday, May 28, 2004 2:07 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] datetime formatting problem

Daniel Clark [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Isn't date a reserved word?

date and dateTime are not reserved in MySQL and can be used as column
names.


  hi all -
 
  this is probably straight forward, but i'm learning and would
  appreciate any insight.
 
  i'm using the datetime type in mysql and have been able to
  successsfully pull the data records's date, but it's failing out and

  giving me the current time [as in what it says on my system's clock]
 
  basically i'm just spitting out all the rows to an html table and
  would like to have the date AND time formatted as is in the
  date(...) function at the top of the code demo.
 
  thanks!
  matt
 
  / begin code demo
 
 
  function formatDate($val)
  {
  $arr = explode(-, $val);
  return date(M d, Y g:i A, mktime(0,0,0, $arr[1], $arr[2],
  $arr[0])); }

Hi Matt,

try this:

function formatDate($val) {
$timestamp = strtotime($val);
return date('M d, Y g:i A', $timestamp); }

Regards, Torsten Roehr

 
 
  // open database connection
  $connection = mysql_connect($host, $user, $pass) or die (Unable to
  connect!);
 
  // select database
  mysql_select_db($db) or die (Unable to select database!);
 
  // generate and execute query
  $query = SELECT * FROM outdoor ORDER BY id ASC; $result =
  mysql_query($query) or die (Error in query: $query.  .
  mysql_error());
 
 
  // if records present
  if (mysql_num_rows($result)  0)
  {
  // iterate through resultset
  // print title with links to edit and delete scripts while($row =
  mysql_fetch_object($result)) { ? tr td? echo $row-id; ?/td

  td? echo $row-name; ?/td tda href=mailto:? echo
  $row-email; ?? echo $row-email; ?/a/td td? echo
  $row-zip ?/td td? echo formatDate($row-date); ?/td td?

  echo $row-club_member ?/td td? echo $row-driver ?/td
  !-- tdfont size=-1? echo $row-active ?/font/td --
 
   tdcentera href=edit.php?id=? echo $row-id; ?img
  src=notepad.gif alt= width=16 height=16 border=0/a a
  href=delete.php?id=? echo $row-id; ?img src=trashcan.gif
  alt= width=16 height=16 border=0/a/center/td /tr ?
  }
  }
 
  --
  PHP General Mailing List (http://www.php.net/) To unsubscribe,
  visit: http://www.php.net/unsub.php
 
 

--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] datetime control

2004-02-09 Thread Angelo Zanetti
is there a date picker object or control that i can use on an HTML page,
instead of making lots of dropdown lists for the various date fields?

thanx in advance
angelo


Disclaimer 
This e-mail transmission contains confidential information,
which is the property of the sender.
The information in this e-mail or attachments thereto is 
intended for the attention and use only of the addressee. 
Should you have received this e-mail in error, please delete 
and destroy it and any attachments thereto immediately. 
Under no circumstances will the Cape Technikon or the sender 
of this e-mail be liable to any party for any direct, indirect, 
special or other consequential damages for any use of this e-mail.
For the detailed e-mail disclaimer please refer to 
http://www.ctech.ac.za/polic or call +27 (0)21 460 3911

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] datetime control

2004-02-09 Thread Tom Rogers
Hi,

Monday, February 9, 2004, 10:42:24 PM, you wrote:
AZ is there a date picker object or control that i can use on an HTML page,
AZ instead of making lots of dropdown lists for the various date fields?

AZ thanx in advance
AZ angelo

AZ 
AZ Disclaimer 
AZ This e-mail transmission contains confidential information,
AZ which is the property of the sender.
AZ The information in this e-mail or attachments thereto is 
AZ intended for the attention and use only of the addressee. 
AZ Should you have received this e-mail in error, please delete 
AZ and destroy it and any attachments thereto immediately. 
AZ Under no circumstances will the Cape Technikon or the sender 
AZ of this e-mail be liable to any party for any direct, indirect, 
AZ special or other consequential damages for any use of this e-mail.
AZ For the detailed e-mail disclaimer please refer to 
AZ http://www.ctech.ac.za/polic or call +27 (0)21 460 3911


http://javascript.internet.com/calendars/date-picker.html

-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] datetime

2003-08-22 Thread Marek Kilimajer
Best and fastest way is to let mysql format the date, look into mysql 
manual for DATE_FORMAT() function.

Dale Hersh wrote:

I am using a mssql database and I have a question regarding the datetime
type. When I write a date to the database it store the date in the following
format:
6/8/03
But when I extract the date from the database it returns the value in the
following format:
Jun 8 2003 12:00AM
Is there a nice function available in php that will format the date based
upon certain specification. I know that date() exists, but I that means I
would have to use mktime() which would require parsing the entire string and
breaking the string into the day, the month, the year. Furthermore, I would
then need a switch statement to convert the value Jun into the value 6.
I appreciate any help.

Thanks,
Dale




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] datetime

2003-08-21 Thread Dale Hersh
I am using a mssql database and I have a question regarding the datetime
type. When I write a date to the database it store the date in the following
format:
6/8/03

But when I extract the date from the database it returns the value in the
following format:
Jun 8 2003 12:00AM

Is there a nice function available in php that will format the date based
upon certain specification. I know that date() exists, but I that means I
would have to use mktime() which would require parsing the entire string and
breaking the string into the day, the month, the year. Furthermore, I would
then need a switch statement to convert the value Jun into the value 6.

I appreciate any help.

Thanks,
Dale



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] datetime

2003-08-21 Thread Larry_Li
Use date() and strtotime() together. strtotime will convert date string 
into integer timestamp. Still have any questions, check these two 
functions online plz.








Dale Hersh [EMAIL PROTECTED]
08/22/2003 10:13 AM
 
To: [EMAIL PROTECTED]
cc: 
Subject:[PHP] datetime
 



I am using a mssql database and I have a question regarding the datetime
type. When I write a date to the database it store the date in the 
following
format:
6/8/03

But when I extract the date from the database it returns the value in the
following format:
Jun 8 2003 12:00AM

Is there a nice function available in php that will format the date based
upon certain specification. I know that date() exists, but I that means I
would have to use mktime() which would require parsing the entire string 
and
breaking the string into the day, the month, the year. Furthermore, I 
would
then need a switch statement to convert the value Jun into the value 6.

I appreciate any help.

Thanks,
Dale



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] datetime

2003-08-21 Thread Cody Phanekham
Convert Jun 8 2003 12:00AM to a timestamp which can then be used with the date() 
function to format the date to whatever format you want.

Lets say you've inserted the date as '6/8/03' and you want the data to remain the same 
when you retrieve it:

?
$ts = strtotime(Jun 8 2003 12:00AM);
echo date(n/j/y, $ts);
?

so all you have to do is replace Jun 8 2003 12:00AM with data retrieved from the DB

 -Original Message-
 From: Dale Hersh [mailto:[EMAIL PROTECTED]
 Sent: Friday, 22 August 2003 12:13
 To: [EMAIL PROTECTED]
 Subject: [PHP] datetime
 
 
 I am using a mssql database and I have a question regarding 
 the datetime
 type. When I write a date to the database it store the date 
 in the following
 format:
 6/8/03
 
 But when I extract the date from the database it returns the 
 value in the
 following format:
 Jun 8 2003 12:00AM
 
 Is there a nice function available in php that will format 
 the date based
 upon certain specification. I know that date() exists, but I 
 that means I
 would have to use mktime() which would require parsing the 
 entire string and
 breaking the string into the day, the month, the year. 
 Furthermore, I would
 then need a switch statement to convert the value Jun into 
 the value 6.
 
 I appreciate any help.
 
 Thanks,
 Dale
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


*
This e-mail, including any attachments to it, may contain confidential and/or personal 
information.
If you have received this e-mail in error, you must not copy, distribute, or disclose 
it, use or take any action 
based on the information contained within it.

Please notify the sender immediately by return e-mail of the error and then delete the 
original e-mail.

The information contained within this e-mail may be solely the opinion of the sender 
and may not necessarily 
reflect the position, beliefs or opinions of Salmat on any issue.

This email has been swept for the presence of computer viruses known to Salmat's 
anti-virus systems.

For more information, visit our website at  www.salmat.com.au.
*


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] datetime

2003-04-03 Thread Tim Haskins
How does one retrieve the date and time off a server in the following
format?

2003-04-03 11:11:38

I've read much on date and time regarding php and mysql but could not figure
out the above format...please help
--
Tim Haskins





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] datetime

2003-04-03 Thread Matt Schroebel

 -Original Message-
 From: Tim Haskins [mailto:[EMAIL PROTECTED] 
 Sent: Thursday, April 03, 2003 2:45 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] datetime
 
 
 How does one retrieve the date and time off a server in the following
 format?
 
 2003-04-03 11:11:38

Plenty of examples here:
http://www.php.net/manual/en/function.date.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] datetime

2003-04-03 Thread Sebastian
$date = date(Y-m-d g:i:s, $date);
echo $date;

cheers,
- Sebastian

 -Original Message-
 From: Tim Haskins [mailto:[EMAIL PROTECTED] 

 How does one retrieve the date and time off a server in the following
 format?
 
 2003-04-03 11:11:38


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] datetime

2003-04-03 Thread Sara Golemon
'g' is 12-hour format, 'H' is 24 hour (with leading 0)

date(Y-m-d H:i:s,$date);

Sebastian [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 $date = date(Y-m-d g:i:s, $date);
 echo $date;

 cheers,
 - Sebastian

  -Original Message-
  From: Tim Haskins [mailto:[EMAIL PROTECTED]

  How does one retrieve the date and time off a server in the following
  format?
 
  2003-04-03 11:11:38




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] datetime convert

2002-09-12 Thread Alex Shi

Hi,

I'm  trying to convert a formated datetime string into a timestamp.
The string format is Y-m-d H:i:s. I use strtotime() to convert the
datetime string. However, the converted datetime seems lost its 
time part. Is there any easy solution to make the converting? 
Thanks in advance!

Alex

-- 
---
TrafficBuilder Network: 
http://www.bestadv.net/index.cfm?ref=7029


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] datetime field - still a newbie

2002-07-25 Thread John Holmes

 I have a datetime field in one of my mysql tables...when displaying
some
 of
 my records I want to display the date in the aforementioned datetime
 field,
 but if the date is today I want to display today instead.  If the
date
 is
 yesterday I want it to display that  so I how do I compare the
date in
 my record to todays date? Thanks

I posted this response earlier...did you get it? Are you looking for a
MySQL solution or a PHP solution??

SELECT IF(TO_DAYS(CURDATE()) =
TO_DAYS(date_column),'Today',IF(TO_DAYS(CURDATE())-1 =
TO_DAYS(date_column),'Yesterday',date_column)) FROM your_table;

If you want a PHP solution, then just select the regular MySQL date
format MMDD and use something like this when looping through your
results.

switch($your_row['Date_Column'])
{
  case date(Ymd):
echo Today;
break;
  case date(Ymd,strtotime(-1 day)):
echo Yesterday;
break;
  default:
echo $your_row['Date_Column'];
}

Untested code, of course...

---John Holmes...




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] datetime field - still a newbie

2002-07-25 Thread Alexander Ross

Thanks bunches


John Holmes [EMAIL PROTECTED] wrote in message
001101c233ba$3de3d430$b402a8c0@mango">news:001101c233ba$3de3d430$b402a8c0@mango...
  I have a datetime field in one of my mysql tables...when displaying
 some
  of
  my records I want to display the date in the aforementioned datetime
  field,
  but if the date is today I want to display today instead.  If the
 date
  is
  yesterday I want it to display that  so I how do I compare the
 date in
  my record to todays date? Thanks

 I posted this response earlier...did you get it? Are you looking for a
 MySQL solution or a PHP solution??

 SELECT IF(TO_DAYS(CURDATE()) =
 TO_DAYS(date_column),'Today',IF(TO_DAYS(CURDATE())-1 =
 TO_DAYS(date_column),'Yesterday',date_column)) FROM your_table;

 If you want a PHP solution, then just select the regular MySQL date
 format MMDD and use something like this when looping through your
 results.

 switch($your_row['Date_Column'])
 {
   case date(Ymd):
 echo Today;
 break;
   case date(Ymd,strtotime(-1 day)):
 echo Yesterday;
 break;
   default:
 echo $your_row['Date_Column'];
 }

 Untested code, of course...

 ---John Holmes...






-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] datetime field - still a newbie

2002-07-24 Thread Alexander Ross

I have a datetime field in one of my mysql tables...when displaying some of
my records I want to display the date in the aforementioned datetime field,
but if the date is today I want to display today instead.  If the date is
yesterday I want it to display that  so I how do I compare the date in
my record to todays date? Thanks

Alex



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] datetime field - still a newbie

2002-07-24 Thread David Freeman

  I have a datetime field in one of my mysql tables...when 
  displaying some of
  my records I want to display the date in the aforementioned 
  datetime field,
  but if the date is today I want to display today instead.  
  If the date is
  yesterday I want it to display that  so I how do I 
  compare the date in
  my record to todays date? Thanks

First up, extract your date as part of your query in a standard format -
if you're looking to do date manipulations you're probably going to be
benefit from extracting it as a unix timestamp.

Once you've got your date information, along with whatever else you're
extracting, you can then process it in php.

You'll most likely have some sort of while() loop to increment through
your query data.

While you're incrementing through you can do an test the date
information against today and yesterday.  Have a read of the php
manual for date() and mktime() as you'll almost certainly need to use
these two functions.

Basically what you'll need to do is test to see if the date information
from your database query is the same as your date information based on
working out what today or yesterday are when expressed in the same
format as the date information from your database.

The rest is pretty much display stuff - substitute date information for
appropriate words as required.

Hope that heads you in the right direction.

CYA, Dave




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] datetime on MSSQL doesn't work with PHP

2001-07-08 Thread Christian Dechery

why does PHP converts the 'datetime' and 'smalldatetime' types of MSSQL to 
a 'prettier' output?

in the table I have '2001-07-01 12:45:01' but when I run a query in PHP to 
get it I recieve 'Jul 7 2001 12:45AM'.
I didn't ask for that... I want the exact value in the field with seconds 
and all, not a converted value. How can I prevent this?

. Christian Dechery (lemming)
. http://www.tanamesa.com.br
. Gaita-L Owner / Web Developer


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]