Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Insert date as dd/mm/yyyy

Guest
Jul 06, 2006 Jul 06, 2006

Copy link to clipboard

Copied

How can I format a form so that I can insert a date as dd/mm/yyyy but it will save it in the database as yyyy-mm-dd?
TOPICS
Server side applications

Views

3.5K
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 06, 2006 Jul 06, 2006

Copy link to clipboard

Copied

tomoslewis wrote:
> How can I format a form so that I can insert a date as dd/mm/yyyy but it will save it in the database as yyyy-mm-dd?

Which server-side language?

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 06, 2006 Jul 06, 2006

Copy link to clipboard

Copied

PHP and MySQL

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 06, 2006 Jul 06, 2006

Copy link to clipboard

Copied

tomoslewis wrote:
> PHP and MySQL

Assuming that your form field is called "date":

$date = explode('/', $_POST['date']);
$mysqlDate = "$date[2]-$date[1]-$date[0]";

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 07, 2006 Jul 07, 2006

Copy link to clipboard

Copied

Where about in the code would I insert that?

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 07, 2006 Jul 07, 2006

Copy link to clipboard

Copied

tomoslewis wrote:
> Where about in the code would I insert that?

I assume from your question that you're using a Dreamweaver Insert
Record server behavior. If that's the case, put this right at the top of
the page that contains the Insert Record server behavior:

<?php
if (isset($_POST['date'])) {
$date = explode('/', $_POST['date']);
$_POST['date'] = "$date[2]-$date[1]-$date[0]";
}
?>

This assumes that your form calls the date field "date". If you have
used a different name, change $_POST['date'] so that the name of the
field is in quotes between the square brackets.

If you're planning to use Dreamweaver to build PHP sites, I strongly
recommend that you learn a little about how the code works, as it will
help you tweak the Dreamweaver code to suit your own needs. Dreamweaver
does a lot for you, but it can't do everything.

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 07, 2006 Jul 07, 2006

Copy link to clipboard

Copied

Thanks!

Once I find a part-time job over the summer, one of the first thing I'm going to buy is a Dreamweaver MYSQL PHP book - any suggestions?

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 07, 2006 Jul 07, 2006

Copy link to clipboard

Copied

tomoslewis wrote:
> Thanks!
>
> Once I find a part-time job over the summer, one of the first thing I'm going to buy is a Dreamweaver MYSQL PHP book - any suggestions?

How about mine. :)

Seriously, though, it's the only book that's exclusively devoted to
using PHP in Dreamweaver. More details here:

http://foundationphp.com/dreamweaver8/

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 03, 2013 Sep 03, 2013

Copy link to clipboard

Copied

Hello, forgive me for reopening the topic after so long closed. It turns out that just today your help was very useful for me, thanks!

I have a very similar question, which is: How to make the dreamweaver grab the date from the database as 'yyyy-mm-dd' and shows on screen as 'dd / mm / yyyy'?

Is this possible?

Thank you!

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 03, 2013 Sep 03, 2013

Copy link to clipboard

Copied

You would use the same basic concept.

Explode the string by characters then create a new string with array items from the exploded result. Assuming your date column is named 'date' in the database you'd perform a query to get the value of the date's row. Then explode the string and create a new string of exploded result.

$mysql_date = explode('-', $mysql_row['date']);

$onscreen_date = "$mysql_date[2]/$mysql_date[1]/$mysql_date[0]";

best,

Shocker

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 03, 2013 Sep 03, 2013

Copy link to clipboard

Copied

hahahah thanks!

After asking the question here, I worked for a while in the code and I did something very similar to what you told me, look:

<input name="datainicial_diaria" type="text" value="

    <?php

    $datainicial=$row_seleciona_diarias['datainicial_diaria'];

    $d=explode("-",$datainicial);

    $datainicial=$d[2]."/".$d[1]."/".$d[0];

    echo $datainicial;

    ?>

">

Is that when you do not have much familiarity with the code generated by dreamweaver, easy things can seem complicated! Thank you!

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Sep 03, 2013 Sep 03, 2013

Copy link to clipboard

Copied

If you are just going to echo the date, the above solutions are fine, but if you need to do various things with the date, such as perform calculations, then it is useful to use the built-in PHP DateTime class instead of the procedural methods. At first it seems like it takes extra steps to do things with the class, but  for some applications it's brilliant.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 04, 2013 Sep 04, 2013

Copy link to clipboard

Copied

mateusaziani wrote:

hahahah thanks!

After asking the question here, I worked for a while in the code and I did something very similar to what you told me, look:

<input name="datainicial_diaria" type="text" value="

    <?php

    $datainicial=$row_seleciona_diarias['datainicial_diaria'];

    $d=explode("-",$datainicial);

    $datainicial=$d[2]."/".$d[1]."/".$d[0];

    echo $datainicial;

    ?>

">

Is that when you do not have much familiarity with the code generated by dreamweaver, easy things can seem complicated! Thank you!

It is not recommended to process data via a form value if the data can simply be processed directly by a query. What I mean to say is that you should be processing your date directly in the processing script instead of sending the value through an input field, which can compromise the data.

best,

Shocker

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Sep 05, 2013 Sep 05, 2013

Copy link to clipboard

Copied

you should be processing your date directly in the processing script instead of sending the value through an input field

There are forms where I populate an input field with a default date, which can then be changed by the person filling out the form, such as arrival and departure dates for a stay at a resort. That might be what the poster is trying to do.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 05, 2013 Sep 05, 2013

Copy link to clipboard

Copied

Rob Hecker2 wrote:

There are forms where I populate an input field with a default date, which can then be changed by the person filling out the form, such as arrival and departure dates for a stay at a resort. That might be what the poster is trying to do.

Are those forms where you populate an input field from data that is originally retrieved from MySQL and reformatted? That seems like an unlikely scenario and sloppy programming.

best,

Shocker

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Sep 06, 2013 Sep 06, 2013

Copy link to clipboard

Copied

LATEST

Shocker, let's say you decide to attend a weeklong retreat titled HOW NOT TO BE A NUISANCE ON INTERNET FORUMS. The registration form is prepopulated with the recommended arrival date of October 3, but you decide to arrive two days earlier, on Oct 1, so you have the ability to change the date and recalculate your costs. Because the retreat center hosts over 500 retreats per year, registration forms are pre-populated with the dates, costs, and other details of the  particular retreat being registered for, which is all stored in the database so a single registration form script can be used for all possible variations.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 07, 2006 Jul 07, 2006

Copy link to clipboard

Copied

Very reasonable price as well! And free delivery!

Just need to find a god damn job now...............

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines