RE: Why doesn't php have a 'date' variable type?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



But it's not a bad point he's trying to make though.  I mean, you could
store the mktime value of a date into a variable and that's sort of the
same as having a date type, but still not quite the same.

I work in PHP as well as VBA on a fairly daily basis and it's kind of
nice in VBA to have a date type and assign like so:

Start_date = '1/1/2004'

Instead of having to do:

$start_date = mktime(0,0,0,1,1,2004);

Or..

$start_date = strtotime("1/1/2004");


And I don't know if it's accurate to say that PHP is typeless, it just
allows explicit as well as implicity variable type casting.  VBA does
this as well, even though it's fairly strictly "typed", but some things
in VBA require you to cast your variable first to make sure you don't
end up with a type mismatch.


I ended up with an odd problem once in PHP that required me to cast the
variable before using it because I was pulling in data from a database
that I needed to determine if a value was numeric (as it was supposed to
be) or if it contained other text (invalid entry).  The database was old
and had been set up before they realized that they really wanted to make
the field an integer field and not varchar.   The first entry I read in
had letters in it, so when I tried to do "is_numeric" in PHP, it always
failed because the first value cast my variable as a string.
Is_numeric checks the variable type, as I found out, not the contents of
the variable.

A date/time type in PHP would be kind of nice I think.

-TG

> -----Original Message-----
> From: Svensson, B.A.T. (HKG) [mailto:B.A.T.Svensson@xxxxxxx] 
> Sent: Thursday, May 20, 2004 5:38 AM
> To: 'php-windows@xxxxxxxxxxxxx '
> Subject: RE:  Why doesn't php have a 'date' variable type?
> 
> 
> > Why doesn't php offer a standard class or variable
> > type to help process dates in a standard manner?
> 
> Maybe because PHP is typeless(?).
> 
> -- 
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

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



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux