Solved

php coding question

Posted on 2009-07-08
10
461 Views
Last Modified: 2012-05-07
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

0
Comment
Question by:glenn_1984
  • 4
  • 4
  • 2
10 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24805640
USE PHP functions strtotime() and date() to perform date conversions and arithmetic.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24805651
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
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24805663
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24805724
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

0
 
LVL 3

Expert Comment

by:cmorbach
ID: 24805736
Here an example
<?php

$mdate = "04/05/06";
 

echo date("F, j, Y", strtotime ($mdate));

?>

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 16

Author Comment

by:glenn_1984
ID: 24808142
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?
0
 
LVL 3

Accepted Solution

by:
cmorbach earned 500 total points
ID: 24808210
Maybe like this...

I'm not sure what values your variables contain.
$rsnew['date_text'] =& date("F, j, Y", strtotime ($ride_calendar->date_text->DbValue));

Open in new window

0
 
LVL 16

Author Comment

by:glenn_1984
ID: 24808359
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.

0
 
LVL 16

Author Comment

by:glenn_1984
ID: 24808364
I will post back when done.
0
 
LVL 16

Author Comment

by:glenn_1984
ID: 24808385
Got it. Just had to change date_text to date at the end fo the line.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Parts and Products table schema in mysql 6 44
Calculating number of days between two dates 7 32
unset shopping cart session 15 32
How do I put a session for a radio button? 4 14
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now