Link to home
Start Free TrialLog in
Avatar of Glenn Abelson
Glenn AbelsonFlag for United States of America

asked on

php coding question

I have some php code (see attached)

If the user entered the DATE as 07/12/2009
how do I automatically update
Month  to July
Day to 12
Year to 2009
day of week to Sunday
// Add record
	function AddRow() {
		global $conn, $Security, $ride_calendar;
		$rsnew = array();
 
		// Field date
		$ride_calendar->date->SetDbValueDef($ride_calendar->date->CurrentValue, ew_CurrentDate());
		$rsnew['date'] =& $ride_calendar->date->DbValue;
 
		// Field Month
		$ride_calendar->Month->SetDbValueDef($ride_calendar->Month->CurrentValue, "");
	    $rsnew['Month'] =& $ride_calendar->Month->DbValue;
 
		// Field day
		$ride_calendar->day->SetDbValueDef($ride_calendar->day->CurrentValue, "");
		$rsnew['day'] =& $ride_calendar->day->DbValue;
 
		// Field year
		$ride_calendar->year->SetDbValueDef($ride_calendar->year->CurrentValue, "");
		$rsnew['year'] =& $ride_calendar->year->DbValue;
 
		// Field day_of_week
		$ride_calendar->day_of_week->SetDbValueDef($ride_calendar->day_of_week->CurrentValue, "");
		$rsnew['day_of_week'] =& $ride_calendar->day_of_week->DbValue;

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

USE PHP functions strtotime() and date() to perform date conversions and arithmetic.
You can test these on my web site here:
http://www.laprbass.com/RAY_strtotime.php

Just type in the date you want to test
Hope this helps you format the values correctly.  Best regards, ~Ray
<?php // RAY_temp_date.php
error_reporting(E_ALL);
 
// TEST DATA FROM THE OP
$dt = '07/12/2009';
 
// CONVERT TO TIMESTAMP
if (!$ts = strtotime($dt)) die("$dt IS NOT A VALID DATE STRING");
 
// SHOW THE DATE FORMAT INFORMATION
echo date("F", $ts);
echo date("j", $ts);
echo date("Y", $ts);
echo date("l", $ts);

Open in new window

Here an example
<?php
$mdate = "04/05/06";
 
echo date("F, j, Y", strtotime ($mdate));
?>

Open in new window

Avatar of Glenn Abelson

ASKER

Thanks for the help...however, I am not really a php programmer and working with existing code.
In my sample above, I need to convert the data for date_text to the strtotime().

I removed the Month, Day, etc field and created a date_text field.

I have been playing with syntax for an hour or so, with no luck.

Here is my current code snippet:

// Add record
      function AddRow() {
            global $conn, $Security, $ride_calendar;
            $rsnew = array();

            // Field date
            $ride_calendar->date->SetDbValueDef($ride_calendar->date->CurrentValue,  ew_CurrentDate());
            $rsnew['date'] =& $ride_calendar->date->DbValue;

            // Field date_text
            $ride_calendar->date_text->SetDbValueDef($ride_calendar->date_text->CurrentValue, "");
            $rsnew['date_text'] =& $ride_calendar->date_text->DbValue;

How do I get the date_text field to automatically fill as the strtotime() ?

Can you help?
ASKER CERTIFIED SOLUTION
Avatar of cmorbach
cmorbach
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, that is the correct track.
Syntax works.
However July 12 came out as July 8 (today).
I need to play with it to grab the data from the field date.

I will post back when done.
Got it. Just had to change date_text to date at the end fo the line.