473,394 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

still having problems with dates

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
5 1803
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Hennie de Nooijer | last post by:
hi thank you for this solution Hugo (dutch?) and it's very handy, thank you but my issue is that we created dozens of views with my function. This functions returns an integer of a date. This...
13
by: Deano | last post by:
Hi, I generate a report using two dates (From and To). I notice if I enter 01/10/2003 that it is interpreted by Access as 10/01/2003 i.e 10th January rather than 1st October as I intended. ...
9
by: Neil | last post by:
I have been coding with ASP for some time now. I am using an ACCESS database. I am in the UK and wish to use DD/MM/YYYY format for dates. I have had no end of problems and possible solutions to...
687
by: cody | last post by:
no this is no trollposting and please don't get it wrong but iam very curious why people still use C instead of other languages especially C++. i heard people say C++ is slower than C but i can't...
8
by: Michael C | last post by:
Hi all, I'm still having problems with VS.NET 2003 running on my XP machine. I finally decided I might as well uninstall completely and reinstall from scratch. But lo and behold it won't let...
2
by: Middletree | last post by:
This could be an Excel thing, but I am not ruling out my ASP code. Using ASP 3.0, I give the user the ability to create a spreadsheet with a click. In the resulting spreadsheet, I have 2 columns...
11
by: garyusenet | last post by:
I have 'cli via c# on order', and in the mean time am reading 'Pro C# 2005 and the .NET platform' (Andrew Troelson). I'm just reading about the 'five types defined in the CTS'. Specifically Struct....
3
by: Brian Simmons | last post by:
Hi all, I'm just having one of those days where seemingly easy problems are giving me a devil of a time. Here's the scenario: Company's fiscal year runs from 10/1/YY -9/30/(YY+1), i.e....
2
by: ncsthbell | last post by:
I am having problems getting the end date to calculate correctly. I start with Quarter '03/02', (YY/QTR), for this it means it is for the 2nd qtr of 2003. My goal is to get the begin & end dates...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.