Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

Date format returned via php different to client


seanc

This topic is 6993 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hi again,

I am in Australia, so all our dates are generally formatted dd/mm/yyyy hh:mm:ss.

This is how dates and timestamps appear in my database when using the client version - without any modifications to the format. The file is set to always use current system settings.

When I display the same field using fx.php, the date is formatted in the US standard mm/dd/yyyy hh:mm:ss.

Is there any way I can show this formatted "correctly"?

Cheers,

Sean.

Link to comment
Share on other sites

  • 2 weeks later...

Hi Garry,

I've been playing around with this and works perfectly for displaying the date correctly, but I can't work out how I can use it for date inputs.

All my users input dates in format d/m/y, and I need to somehow convert that to m/d/y when sending to filemaker.

I can then use what you already suggested for displaying the results.

I've tried as many things as I can think of, but coming up against a wall...

Would you be able to point me in the right direction?

Thanks in advance!

Sean.

Link to comment
Share on other sites

The safest way to enter dates on the web is by using a calendar (you'll get the same output every time) or using three pulldown menu's: day, month, year. Then of course, help your webusers by entering the right (current) date.

Don't trust web users, trust the technology. :) There's too many ways to enter dates.

Edited by Guest
Link to comment
Share on other sites

Hi, S! I'm not sure how much PHP you do, but you can probably use substr( ) or explode( ) to parse the date string entered and rearrange it before passing it to FM, or you could convert it to unix epoch or yyyymmdd and store it as an integer in FM, but I suppose it depends on what you're doing.

Here's a function I use to convert from ymd to mdy that you can probably adapt to do dmy to mdy but you'll have to add stuff to account for leading zeros and range checking so maybe explode( ) would be better. Here it is anyway, though...

FUNCTION ymd_to_mdy ($mysqldate)

{

$year = substr ($mysqldate, 0, 4);

$month = substr ($mysqldate, 5, 2);

$day = substr ($mysqldate, 8, 2);

$mdydate = $month . "-" . $day . "-" . $year;

return $mdydate;

}

--ST

Link to comment
Share on other sites

Here is a Javascript method of inputing a date (you can do a similar thing with PHP):)

     

function daylist()

{

today =  new Date();

day = today.getDate();

daydisp = "";

for (i=1; i<32; i++)

{

if (i == day)

{ daydisp += '' +i;}

else

{ daydisp += '' +i;};

};

return daydisp;

}



function monthlist()

month = today.getMonth() + 1;

monthdisp = "";

for (i=1; i<13; i++)

{

if (i == month)

{ monthdisp += '' +i;}

else

{ monthdisp += '' +i;};

};

return monthdisp;

}



function yearlist()

{

year = today.getFullYear();

yeardisp = "";

for (i=2005; i<2010; i++)

{

if (i == year)

{ yeardisp += '' + i;}

else

{ yeardisp += '' + i;};

};

return yeardisp;

}



Here is the BODY stuff:


	

		Date Serviced:



      							

      							



		      					

		      					



		       					



Checked by:

Report Date:



     							

     							



		      					

		      					



		       					



	

You can then reorganise the format (with PHP) after the Form is submitted for processing.

All the best.

Garry

Link to comment
Share on other sites

  • 3 weeks later...

These calcs help me a lot transferring data to unix, FM, PHP and back... very versatile and complying to PHP standards.

Dates are always a problem, this calculation makes it easier.

<?php

// date calculations

?>



<?

//array combine (if you dopn't have PHP5, you'll need this too.



if (!function_exists('array_combine')) {

   function array_combine($a1, $a2) {

       if(count($a1) != count($a2))

           return false;

           if(count($a1) <= 0)

           return false;

       $a1 = array_values($a1);

       $a2 = array_values($a2);

       $output = array();

       for($i = 0; $i < count($a1); $i++) {

           $output[$a1[$i]] = $a2[$i];

       }

       return $output;

   }}



/* Date calculations

Syntax: dateFormat($mydate, 'd/m/y', 'Y-m-d')

$mydate = "16/04/02";

echo ('date input: '.$mydate.' -> date output: '.dateFormat($mydate, 'd/m/y', 'Y-m-d'));

*/



function dateFormat($input_date, $input_format, $output_format) {

   preg_match("/^([w]*)/i", $input_date, $regs);

   $sep = substr($input_date, strlen($regs[0]), 1);

   $label = explode($sep, $input_format);

   $value = explode($sep, $input_date);

   $array_date = array_combine($label, $value);

   if (in_array('Y', $label)) {

       $year = $array_date['Y'];

   } elseif (in_array('y', $label)) {

       $year = $year = $array_date['y'];

   } else {

       return false;

   }



   $output_date = date($output_format, mktime(0,0,0,$array_date['m'], $array_date['d'], $year));

   return $output_date;

}



?>

Good luck.

Hartger

Link to comment
Share on other sites

This topic is 6993 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.