I have table in mysql and contains date(date) which is contains 2070-06-30.
When I provide the following statement in php
echo date('d-m-Y', strtotime($row['date']));
it gives 01-01-1970.
How I get my desire date of table field.
please help?
Adil
date help?
Moderator: General Moderators
Re: date help?
Just to be clear, when you echo the value pulled from the database, is it "2070-06-30"? I'm pretty sure that format is not compatible with PHP's strtotime() function. You'd have to do a strreplace to replace '-' with '/', and then try strtotime on the replaced string. Additionally, I don't see where you are using the date function. Just echoing the strtotime would give you 0 if it cannot read the date properly; you'd have to use date() on the strtotime converted value in order to display the date you want.
For now, try switching the hyphens to slashes. If that doesn't work, let me know.
For now, try switching the hyphens to slashes. If that doesn't work, let me know.
Re: date help?
Instead of using PHP strtotime use MYSQL function STR_TO_DATE(str,format), which will be easy.
Re: date help?
Won't a simple date('Y-m-d') do it? The first parameter determines the format right?
DateTime class
If you have php 5.2 you can use the DateTime class:
I recently did a project with Mortgage amortization dates. A 30 year mortgage puts you beyond the 2038 limit of `date()`. But DateTime can go from -9999 to 9999. MySQL's range is from 1000 to 9999
If you do not have php 5.2, I believe Zend_Date can handle dates past 2038.
Code: Select all
$date = new DateTime('2070-06-30');
echo $date->format('d-m-Y');If you do not have php 5.2, I believe Zend_Date can handle dates past 2038.