Glenn Abelson
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
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;
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
http://www.laprbass.com/RAY_strtotime.php
Just type in the date you want to test
Man pages here:
http://us.php.net/manual/en/function.strtotime.php
http://us.php.net/manual/en/function.date.php
HTH, ~Ray
http://us.php.net/manual/en/function.strtotime.php
http://us.php.net/manual/en/function.date.php
HTH, ~Ray
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);
Here an example
<?php
$mdate = "04/05/06";
echo date("F, j, Y", strtotime ($mdate));
?>
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->SetD bValueDef( $ride_cale ndar->date ->CurrentV alue, ew_CurrentDate());
$rsnew['date'] =& $ride_calendar->date->DbVa lue;
// Field date_text
$ride_calendar->date_text- >SetDbValu eDef($ride _calendar- >date_text ->CurrentV alue, "");
$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?
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->SetD
$rsnew['date'] =& $ride_calendar->date->DbVa
// Field date_text
$ride_calendar->date_text-
$rsnew['date_text'] =& $ride_calendar->date_text-
How do I get the date_text field to automatically fill as the strtotime() ?
Can you help?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
ASKER
I will post back when done.
ASKER
Got it. Just had to change date_text to date at the end fo the line.