Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-10-2007, 06:26 AM
Junior Member
 
Join Date: Jul 2007
Posts: 3
Default Getting the date format

Please hit me if I'm wrong, but I couldn't find a method that returns a string representation of the date format currently used to format the date. I need a method that returns something like "dd.mm.yyyy" if the current format is Zend_Date::DATE_MEDIUM. Such a string representation f.i. is used by the JQuery table sorter which then can sort table columns of the given date format. But maybe I'm just blind ;) Hope you can help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-13-2007, 02:37 PM
Junior Member
 
Join Date: Jul 2007
Posts: 4
Default

Hello,

You can find a list of date constants at: framework.zend.com/manual/en/zend.date.constants.html#zend.date.constants.list

Something like this would work for you:

$myDate = new Zend_Date(strtotime('2007-07-13'));
$myDate->toString("dd.MM.YYYY");

Cheers
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-14-2007, 02:54 PM
Junior Member
 
Join Date: Jul 2007
Posts: 3
Default

Sorry, but it seems you got me wrong. The problem is, that I'm running a multi-language site. That's why I'm only using the localized constants like DATE_LONG, DATE_MEDIUM, etc.

I'm looking for a way to get the underlying format for the current locale behind DATE_MEDIUM. The "dd.mm.yyyy" I wrote was just an example what DATE_MEDIUM may currently look like in a german locale f.i. And I didn't find a method that simply returns this string representation of the format that's currently used as DATE_MEDIUM, DATE_LONG, etc.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-20-2007, 10:28 PM
Junior Member
 
Join Date: Jul 2007
Posts: 4
Default

Zend_Date takes locale as a parameter. So you can also try:

$myDate = new Zend_Date(strtotime('2007-07-13'), false, 'de');

and this should convert dates to their localized formats. Sorry but I am not too sure about using the localized constants like DATE_LONG to automatically make dates in their locale format. Perhaps use the above and play around with toString() to see what you can get.

I am also now working on a multi-lingual site and am playing around with dates, so if I come across anything I will post it.

Cheers
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-24-2007, 05:26 PM
Junior Member
 
Join Date: Jul 2007
Posts: 3
Default

There's a method located inside the Zend_Locale class that helps a bit. But it's not quite 100% percent what I was looking for.

Code:
Zend_Locale_Format::getDateFormat($locale]);
It seems that this method returns a string representation for

Code:
Zend_Date::DATE_MEDIUM
It would be better to have an interface for all localized date constants but at least that's a beginning
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 11-27-2007, 12:22 AM
Junior Member
 
Join Date: Nov 2007
Posts: 23
Default Zend_Date::now doesn't store the correct date in the DB

Hi, I have a field database field called created_at which is assigned when an new instance is created and I use the following:

PHP Code:
$data = array( 'created_at' =>  Zend_Date::now() );

$object = new MyClass();

$object->insert$data ); 
However, when I list the objects that have been inserted in the database via the browser, I'm getting the following for the 'created_at' field:

0000-00-00 00:00:00

Also, when I view the contents of the DB, I'm seeing the same results. Thus, if anyone has the answer for this, please post the solution.

Thanks in advance,

-Conrad
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 11-28-2007, 01:25 AM
Elemental's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 119
Default

re: mosh

did you find a way to get what you were after?

re: conradwt

Zend_Date::now() returns a Zend_Date object, you need to turn it into a timestamp or string via:

Code:
Zend_Date::now()->toString();
//or
Zend_Date::now()->getTimestamp();
note: toString() takes formatting, locale and something else as parameters, check the api docs at zend.com for details.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 11-28-2007, 04:34 AM
Junior Member
 
Join Date: Nov 2007
Posts: 23
Default Re: Getting the date format

Quote:
Originally Posted by Elemental View Post
re: mosh

did you find a way to get what you were after?

re: conradwt

Zend_Date::now() returns a Zend_Date object, you need to turn it into a timestamp or string via:

Code:
Zend_Date::now()->toString();
//or
Zend_Date::now()->getTimestamp();
note: toString() takes formatting, locale and something else as parameters, check the api docs at zend.com for details.
Hi, I was able to find the following in the reference documentation:

PHP Code:
new Zend_Db_Expr('NOW()'
However, it seems that the toString method is called when I invoke the following test action:

PHP Code:
function dateAction()
{
   
$this->view->current_date Zend_Date::now();

Now, when I invoke the action (i.e. http://localhost/my_app/public/admin/date ), it prints the time and the date as I would expect. In any case, I'll try your method of obtaining the timestamp from the Date instance.

Thanks again,

-Conrad
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-23-2008, 06:41 AM
Member
 
Join Date: Feb 2008
Posts: 46
Question

I have used Data class and found some mismatch of date usage. How to solve this?

in pHP: date("Y-m-d"): gives 2008-02-23
in zf : $date->toString("Y-m-d"); give 2008-i-23 like that. Time also coming like that . how to solve this and how to take the time 05:25:04 and date 2008-02-25?

- mugesh
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-02-2008, 11:01 AM
Junior Member
 
Join Date: Jun 2007
Location: Barcelona
Posts: 8
Default

Quote:
Originally Posted by murugesanme View Post
I have used Data class and found some mismatch of date usage. How to solve this?

in pHP: date("Y-m-d"): gives 2008-02-23
in zf : $date->toString("Y-m-d"); give 2008-i-23 like that. Time also coming like that . how to solve this and how to take the time 05:25:04 and date 2008-02-25?

- mugesh
Letters used by PHP in date() are different than the ones used by ZF.
use $date->get('YYYY-MM-dd HH:mm:ss') to show both date and time, or $date->get('YYYY-MM-dd') to show date only.
__________________
------------------
Loris Candylaftis
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:29 PM.