473,811 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1824
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($date val));

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
visitorscomment s 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($date val));

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************ *************** *************** @spamyourself.c om> 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
visitorscomment s 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
1747
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 function has to give a lowerlimit and higherlimit back when dates are out of Calendar range. But i want to read this from the Calendartable ONCE and store it in a global variable somewhere in SQL Server. I DON'T want to reference tables in my...
13
3100
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. This is the old problem of US date format mm/dd/yy versus dd/mm/yy. I am stepping through the code and the dates do seem to be ok but when the report runs I get records earlier than 1st October which is not what I want.
9
1910
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 dates such as 1/8/05 being interpreted in the wrong way. I have been given many suggestions (setting LCID, submitting dates in long format etc. etc.) Is there any definitive sloution or tutorial available? This is driving me
687
23792
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 believe that. in pieces of the application where speed really matters you can still use "normal" functions or even static methods which is basically the same. in C there arent the simplest things present like constants, each struct and enum...
8
1732
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 me uninstall... It gets stuck about 2/3rds of the way through the uninstall (based on the progress bar) and hangs for a very, very long time (a few hours last time). Then it seems to give up and returns an error message stating that it cannot...
2
1293
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 which contain dates, and which were created by almost exactly the same code, yet they behave differently when I try to sort. First, go to http://www.middletree.net/get.htm and right-click and save the Excel file, then open it.
11
2379
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. Now Troelson described the struct type as 'a lightweight class type having value based semantics'. Looking at his example I cant see any difference from a class here other than it is defined with the struct keyword? what is the difference...
3
1525
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. 10/1/2006 -> 9/30/2007 Users are required to enter a FromDate and ToDate for services needed.
2
5863
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 for each 'month' in the quarter, hence, I want to calculate the begin & end of the month dates for April, May & June 2003 : so my starting point is: firstMonthBegin = vcBegMM & "/" & vcBegDD & "/" & vcBegYY firstMonthEnd = vcEndMM &...
0
10648
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10389
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10402
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9205
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6890
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3867
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3018
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.