Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

php long error

Explorer ,
Mar 18, 2012 Mar 18, 2012

I have the following code and input, and am getting this error:

code:

$date = date('D, d M Y H:i:s', $date);

input:

1332092255

error:

Warning:  date() expects parameter 2 to be long, string given in (page) on line 72

TOPICS
Server side applications
960
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 18, 2012 Mar 18, 2012

What is the value in $date before calling the date() function? Where is it coming from? Is it a string or int?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 18, 2012 Mar 18, 2012

the value is 1332092255.  it comes from mysql database.  i have it listed as varchar there.  not sure that that should affect it though. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 18, 2012 Mar 18, 2012

The PHP reference manual lists the argument as an int, so storing it as a varchar would defintely cause a problem in that regard. However, the error message is confusing, making it sound like it would accept a string value. I'm not sure how to interpret that.  Why are you storing it as a varchar in the first place? It's a numeric value and should be stored as such. For a quick test, try casting it as an int

$date = date('D, d M Y H:i:s', (int)$date);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 18, 2012 Mar 18, 2012

ah, i think i remember now... i had it set to varchar because when i had it set to int, it was cutting of characters, and i wasnt sure what was bigger than int, so i just used varchar.  what should i use for this field to make sure nothing gets cut off?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 18, 2012 Mar 18, 2012

An unsigned int should do it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 19, 2012 Mar 19, 2012

what about BIGINT?

and what does "unsigned" mean?  does it mean, no set value length?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 19, 2012 Mar 19, 2012
LATEST

It should not need to be as big as a BIGINT. Did you try the casting test I suggested?

Unsigned means that it does not store negative numbers. By default, numeric datatypes are signed, so they support both negative and positive. Unsigned means that only positive values can be stored. As a result, unsigned columns can store twice as many values as signed. Still, given the values of unix time stamp, a signed int should work.

As a troubleshooting measure, try the code I suggested a few posts back.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines