By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,983 Members | 1,582 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,983 IT Pros & Developers. It's quick & easy.

still having problems with dates

P: n/a
Hi

I am niew to pho and am having trouble with dates.

I can format a date ok
so $today=date('d M Y' )
gives me 2 Nov 2005
$dateval is a mysql date
yyyy-mm-dd hh:nn:sss (2005-10-26 13:32:09)
$today=date('d M Y' ,$dateval)
gives me something like 1 july 1970

I am not sure how to tell the php that the date is a date.

It is driving me nuts, and the only particulary
obscure thing I have encountered so far.

i would be grateful for some advice

thanks

jonathan



===============
Jonathan Crawford
jc@tgsi.net
===============
Nov 4 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Jonathan Crawford wrote:
I am niew to pho and am having trouble with dates.

I can format a date ok
so $today=date('d M Y' )
gives me 2 Nov 2005
$dateval is a mysql date
yyyy-mm-dd hh:nn:sss (2005-10-26 13:32:09)
$today=date('d M Y' ,$dateval)
gives me something like 1 july 1970


Hi Jonathan,

Try:

$today=date('d M Y', strtotime($dateval));

HTH.
Peter.

--
http://www.phpforums.nl
Nov 4 '05 #2

P: n/a
Jonathan Crawford wrote:
Hi

I am niew to pho and am having trouble with dates.
Read the manual. :-)
Really, it is the only things that helps.
www.php.net

I can format a date ok
so $today=date('d M Y' )
gives me 2 Nov 2005
which is fine.
Except for the fact it is 4 november over here, is your time ok?


$dateval is a mysql date
yyyy-mm-dd hh:nn:sss (2005-10-26 13:32:09)
$today=date('d M Y' ,$dateval)
And here you go wrong.

Did you read what date() does in PHP?
Check the manual: It says:

-----------------------------------------
Description
string date ( string format [, int timestamp] )
Returns a string formatted according to the given format string using the
given integer timestamp or the current local time if no timestamp is given.
In other words, timestamp is optional and defaults to the value of time().

Note: To generate a timestamp from a string representation of the date, you
may be able to use strtotime(). Additionally, some databases have functions
to convert their date formats into timestamps (such as MySQL's
UNIX_TIMESTAMP function).

-----------------------------------------

So.....

What you should do is:
1) read the manual
2) make sure you know how your date is represented in mySQL, and how PHP
wants it. Have a look at strtotime() and the like for help.

In general: if a function is not behaving as expected, read the manual and
see what is says.
On www.php.net: if you cannot find your problem/answer, be sure to read the
visitorscomments too, they often contain usefull information.
gives me something like 1 july 1970

I am not sure how to tell the php that the date is a date.

It is driving me nuts, and the only particulary
obscure thing I have encountered so far.
rtfm.

i would be grateful for some advice

thanks

jonathan


Good luck!

Regards,
Erwin Moller
Nov 4 '05 #3

P: n/a
thanks ever so much,
that was just what I needed and it does
make sense to me now.

thanks

jc

--
===============
Jonathan Crawford
jc@tgsi.net
===============
"Peter van Schie" <va************@gmail.com> wrote in message
news:43***********************@news.xs4all.nl...
Jonathan Crawford wrote:
I am niew to pho and am having trouble with dates.

I can format a date ok
so $today=date('d M Y' )
gives me 2 Nov 2005
$dateval is a mysql date
yyyy-mm-dd hh:nn:sss (2005-10-26 13:32:09)
$today=date('d M Y' ,$dateval)
gives me something like 1 july 1970


Hi Jonathan,

Try:

$today=date('d M Y', strtotime($dateval));

HTH.
Peter.

--
http://www.phpforums.nl

Nov 4 '05 #4

P: n/a
thanks, I will read the manual,
but sometimes time pressure makes
that a little difficult.

I appreciate your effort and actually
understand it now

thanks

jonathan

--
===============
Jonathan Crawford
jc@tgsi.net
===============
"Erwin Moller"
<si******************************************@spam yourself.com> wrote in
message news:43***********************@news.xs4all.nl...
Jonathan Crawford wrote:
Hi

I am niew to pho and am having trouble with dates.


Read the manual. :-)
Really, it is the only things that helps.
www.php.net

I can format a date ok
so $today=date('d M Y' )
gives me 2 Nov 2005


which is fine.
Except for the fact it is 4 november over here, is your time ok?


$dateval is a mysql date
yyyy-mm-dd hh:nn:sss (2005-10-26 13:32:09)
$today=date('d M Y' ,$dateval)


And here you go wrong.

Did you read what date() does in PHP?
Check the manual: It says:

-----------------------------------------
Description
string date ( string format [, int timestamp] )
Returns a string formatted according to the given format string using the
given integer timestamp or the current local time if no timestamp is
given.
In other words, timestamp is optional and defaults to the value of
time().

Note: To generate a timestamp from a string representation of the date,
you
may be able to use strtotime(). Additionally, some databases have
functions
to convert their date formats into timestamps (such as MySQL's
UNIX_TIMESTAMP function).

-----------------------------------------

So.....

What you should do is:
1) read the manual
2) make sure you know how your date is represented in mySQL, and how PHP
wants it. Have a look at strtotime() and the like for help.

In general: if a function is not behaving as expected, read the manual and
see what is says.
On www.php.net: if you cannot find your problem/answer, be sure to read
the
visitorscomments too, they often contain usefull information.
gives me something like 1 july 1970

I am not sure how to tell the php that the date is a date.

It is driving me nuts, and the only particulary
obscure thing I have encountered so far.


rtfm.

i would be grateful for some advice

thanks

jonathan


Good luck!

Regards,
Erwin Moller

Nov 4 '05 #5

P: n/a
Jonathan Crawford wrote:

Hi Jonathan,
thanks, I will read the manual,
but sometimes time pressure makes
that a little difficult.
Yes, I know how it is.
IMHO:
Sometimes it is better to tell your boss/client/whatever you will be a week
later with the project because if you hurry, you will deliver code you
yourself don't trust.
Sometimes they even understand that.
;-)


I appreciate your effort and actually understand it now

Good. :-)

Good luck with the project!

Regards,
Erwin Moller

thanks

jonathan

Nov 7 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.