Date format

Hi,

I have a form that there are 2 date fields on that I assume are pulling the date format form the database as the standard Joomla date formats do not affect it. I have posted the entire code for default.php below.
I’ve done a fair bit of searching and have a basic understanding of the various arguments for date format, but as I know nothing about php I’m having problems as to where to put this code. The 2 fields are “order” and “due”. I click on the calendar for the date I want and the format it comes out as is YYYY-MM-DD. I want it as DD-MM-YYYY. Could anybody help me with what to put in and where to achieve this?

[php]<?php
/**

  • @version 1.0.0
  • @package com_jobs
  • @copyright Copyright © 2013. All rights reserved.
  • @license GNU General Public License version 2 or later; see LICENSE.txt
  • @author
    */
    // no direct access
    defined(’_JEXEC’) or die;

//Load admin language file
$lang = JFactory::getLanguage();
$lang->load(‘com_jobs’, JPATH_ADMINISTRATOR);
$canEdit = JFactory::getUser()->authorise(‘core.edit’, ‘com_jobs.’ . $this->item->id);
if (!$canEdit && JFactory::getUser()->authorise(‘core.edit.own’, ‘com_jobs’ . $this->item->id)) {
$canEdit = JFactory::getUser()->id == $this->item->created_by;
}
?>

<?php if ($this->item) : ?>
<div class="item_fields">
<?php echo date('new_format',strtotime($item->due)); ?>
        			<li><?php echo JText::_('COM_JOBS_FORM_LBL_TASK_CREATED_BY'); ?>:
		<?php echo $this->item->created_by; ?></li>
		<li><?php echo JText::_('COM_JOBS_FORM_LBL_TASK_ID'); ?>:
		<?php echo $this->item->id; ?></li>
		<li><?php echo JText::_('COM_JOBS_FORM_LBL_TASK_JOB_NUMBER'); ?>:
		<?php echo $this->item->job_number; ?></li>
		<li><?php echo JText::_('COM_JOBS_FORM_LBL_TASK_JOB_TITLE'); ?>:
		<?php echo $this->item->job_title; ?></li>
		<li><?php echo JText::_('COM_JOBS_FORM_LBL_TASK_CUSTOMER'); ?>:
		<?php echo $this->item->customer; ?></li>
		<li><?php echo JText::_('COM_JOBS_FORM_LBL_TASK_SITES'); ?>:
		<?php echo $this->item->sites; ?></li>
		<li><?php echo JText::_('COM_JOBS_FORM_LBL_TASK_ORDER'); ?>:
		<?php echo $this->item->order; ?></li>
		<li><?php echo JText::_('COM_JOBS_FORM_LBL_TASK_DUE'); ?>:
		<?php echo $this->item->due; ?></li>
		<li><?php echo JText::_('COM_JOBS_FORM_LBL_TASK_PO'); ?>:
		<?php echo $this->item->po; ?></li>
		<li><?php echo JText::_('COM_JOBS_FORM_LBL_TASK_JOB_DESCRIPTION'); ?>:
		<?php echo $this->item->job_description; ?></li>
		<li><?php echo JText::_('COM_JOBS_FORM_LBL_TASK_PROGRESS'); ?>:
		<?php echo $this->item->progress; ?></li>
		<li><?php echo JText::_('COM_JOBS_FORM_LBL_TASK_INVOICE'); ?>:
		<?php echo $this->item->invoice; ?></li>
		<li><?php echo JText::_('COM_JOBS_FORM_LBL_TASK_STATE'); ?>:
		<?php echo $this->item->state; ?></li>


    </ul>

</div>
<?php if($canEdit): ?>
	<a href="<?php echo JRoute::_('index.php?option=com_jobs&task=task.edit&id='.$this->item->id); ?>"><?php echo JText::_("COM_JOBS_EDIT_ITEM"); ?></a>
<?php endif; ?>
							<?php if(JFactory::getUser()->authorise('core.delete','com_jobs.task.'.$this->item->id)):
							?>
								<a href="javascript:document.getElementById('form-task-delete-<?php echo $this->item->id ?>').submit()"><?php echo JText::_("COM_JOBS_DELETE_ITEM"); ?></a>
								<form id="form-task-delete-<?php echo $this->item->id; ?>" style="display:inline" action="<?php echo JRoute::_('index.php?option=com_jobs&task=task.remove'); ?>" method="post" class="form-validate" enctype="multipart/form-data">
									<input type="hidden" name="jform[created_by]" value="<?php echo $this->item->created_by; ?>" />
									<input type="hidden" name="jform[id]" value="<?php echo $this->item->id; ?>" />
									<input type="hidden" name="jform[job_number]" value="<?php echo $this->item->job_number; ?>" />
									<input type="hidden" name="jform[job_title]" value="<?php echo $this->item->job_title; ?>" />
									<input type="hidden" name="jform[customer]" value="<?php echo $this->item->customer; ?>" />
									<input type="hidden" name="jform[sites]" value="<?php echo $this->item->sites; ?>" />
									<input type="hidden" name="jform[order]" value="<?php echo $this->item->order; ?>" />
									<input type="hidden" name="jform[due]" value="<?php echo $this->item->due; ?>" />
									<input type="hidden" name="jform[po]" value="<?php echo $this->item->po; ?>" />
									<input type="hidden" name="jform[job_description]" value="<?php echo $this->item->job_description; ?>" />
									<input type="hidden" name="jform[progress]" value="<?php echo $this->item->progress; ?>" />
									<input type="hidden" name="jform[invoice]" value="<?php echo $this->item->invoice; ?>" />
									<input type="hidden" name="jform[state]" value="<?php echo $this->item->state; ?>" />
									<input type="hidden" name="option" value="com_jobs" />
									<input type="hidden" name="task" value="task.remove" />
									<?php echo JHtml::_('form.token'); ?>
								</form>
							<?php
							endif;
						?>
<?php else: echo JText::_('COM_JOBS_ITEM_NOT_LOADED'); endif; ?>[/php]

Walktrough

google search: PHP convert date yyyy-mm-dd to dd-mm-yyyy

http://paulcracknell.net/983/php-convert-date-yyyy-mm-dd-to-dd-mm-yyyy/

[php]//This is the function
function changeDate($backwardsDate){
$newDate = date(“d-m-Y”, strtotime($backwardsDate));
return $newDate;
}[/php]

Now we probably don’t need the function, so we’ll just do the conversion
[php]date(“d-m-Y”, strtotime($backwardsDate));[/php]

–>

[php]

<?php echodate("d-m-Y", strtotime($this->item->due)); ?>[/php]

This is untested so if you get any trouble just come back here and we’ll get you sorted :slight_smile:

Hi thanks for the help. Problem is I really dont have a clue what im doing (just started going through the tutorials from this site). I pasted in the code as you kindly did for me, but it had no effect. Could you help me understand where the function comes into the equation? Also where is ‘new_format’ called from or is just a description?

Sorry was having a moment there - I’ve entered the code exactly as you said with new_format being ‘d-m-Y’ but it has had no effect?

Not sure what to tell you, it works.

[php]<?php
ini_set(‘error_reporting’, E_ALL);
ini_set(‘display_errors’, ‘1’);
date_default_timezone_set(‘Europe/Oslo’);

function changeDate($backwardsDate){
$newDate = date(“d-m-Y”, strtotime($backwardsDate));
return $newDate;
}

$date = ‘2013-10-12’;
echo changeDate($date);[/php]

Find your timezone here: http://us3.php.net/manual/en/timezones.php

Output:

12-10-2013

Thanks again - it’s just me not understanding where the strings come from and what to do with them. I’m a bit of a hopeless case I’m afraid. I’ll make a backup of my original and just keep playing till I get it.

Have you tried changing line 40-42
[php]<?php echo $this->item->order; ?>

  • <?php echo JText::_('COM_JOBS_FORM_LBL_TASK_DUE'); ?>: <?php echo $this->item->due; ?>
  • [/php]

    to this
    [php]<?php echo date("d-m-Y", strtotime($this->item->order)); ?>

  • <?php echo JText::_('COM_JOBS_FORM_LBL_TASK_DUE'); ?>: <?php echo date("d-m-Y", strtotime($this->item->due)); ?>
  • [/php]

    ps: you also need to set a proper timezone adding this to the top of your script
    [php]date_default_timezone_set(‘Europe/Oslo’)[/php]

    Just tried it - no luck. Im searching around to find out where it calls ‘order’ and ‘due’ from to see if I can change it before it is called.

    Just noticed you won’t help if using mysql - I think this may be the issue? To be honest I’m not really sure what it’s using - it’s a Joomla installation

    It shouldn’t matter… It doesn’t call order and due as they are not functions, they are properties (variables) in the item object.

    Could you try to var_dump($this->item->order) ?

    I see - what was puzzling me was trying to apply a basic logic to it that ‘due’ gets the variable from an xml file that states that it’s type is ‘calendar’, so figured it was just outputting that value. I tried to add a format line to the xml file, but had no joy with that either. Got to leave this for a while now - lunch and then getting ready to go out tonight, so won’t get chance to work on it again for some time. Thanks again for your help. I’ll go through all your suggestions again with a fresh head as soon as I get time.

    Sponsor our Newsletter | Privacy Policy | Terms of Service