I am trying to put a date in my database in the form dd-mm-yyy, as for
my PHP page is returns 3 variables $date, $month, $year. is ther a way
to put these together? i have tried imploding them but i can't seem to
get them into an array!
here is my code:
$array = array();
$array[] = $Day;
$array[] = $month;
$array[] = $year;
$comma_separated = implode("-", $array);
Thanks
Ben 8 8036
ben3003 wrote: I am trying to put a date in my database in the form dd-mm-yyy, as for my PHP page is returns 3 variables $date, $month, $year. is ther a way to put these together? i have tried imploding them but i can't seem to get them into an array!
here is my code:
$array = array(); $array[] = $Day; $array[] = $month; $array[] = $year;
$comma_separated = implode("-", $array);
What do you mean? You are constructing a string from an array and want
to construct an array from that string? Using explode instead of implode
does this, but your intension is unclear to me...
JW
sorry JW,
I have 3 variables arrive at this page through a POST from a form. it
is a date. However it is in the form 3 variables rater than 1 variable.
the 3 variables are day, month, and year. form here i want to insert
the values into one filed of my MySQL database in the form dd-mm-yyy.
Does this make it clear?
i presumed that an implode function would be best for this.
Ben
ben3003 wrote: I am trying to put a date in my database in the form dd-mm-yyy, as for my PHP page is returns 3 variables $date, $month, $year. is ther a way to put these together? i have tried imploding them but i can't seem to get them into an array!
here is my code:
$array = array(); $array[] = $Day; $array[] = $month; $array[] = $year;
$comma_separated = implode("-", $array);
Ugly, but it should have worked. This is neater:
$dash_separated = implode("-", array($day,$month,$year));
but this is better:
$dash_separated = sprintf("%02d-%02d-%04d",$day,$month,$year);
C.
Perhaps register-globals is off (like it shoud be)?
$dash_separated = implode("-",
array($_POST['day'],$_POST['month'],$_POST['year']));
ben3003 wrote: I have 3 variables arrive at this page through a POST from a form. it is a date. However it is in the form 3 variables rater than 1 variable. the 3 variables are day, month, and year. form here i want to insert the values into one filed of my MySQL database in the form dd-mm-yyy.
Is there a compelling reason to not store the date in the standard SQL
format 'YYYY-MM-DD'?
$datestring = "$year-$month-$Day";
Or "$Day-$month-$year" if you really want that order.
JP
--
Sorry, <de*****@cauce.org> is a spam trap.
Real e-mail address unavailable. 5000+ spams per month.
.oO(Jan Pieter Kunst) Is there a compelling reason to not store the date in the standard SQL format 'YYYY-MM-DD'?
$datestring = "$year-$month-$Day";
It could be necessary to use sprintf() to add leading zeros.
Micha
ok well i am using:
$day = $_POST['StartDay'];
$month = $_POST['StartMn'];
$year = $_POST['StartYr'];
$dash_separated = sprintf("%d-%d-%d",$day,$month,$year);
echo $dash_separated;
and for some reason i am getting the folowing output:
13-0-0
This should be:
13-01-2001
any one?
Ben
$day = $_POST['StartDay'];
$month = $_POST['StartMn'];
$year = $_POST['StartYr'];
$dash_separated = sprintf("%d-%d-%d",$day,$month,$year);
echo $dash_separated;
this currently is returning
13-00-00
when i would like
13-01-2005
any ideas? thanks ben This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: chad phillips |
last post by:
Hi,
(Newbie to php). I am trying to read in a list of ids. Here is my
url
http://localhost/a.php?id=1&id=2&id=3
Then I just want to print out the ids, but I can't seem to get it
work. I...
|
by: Geoff Berrow |
last post by:
I don't particularly need to do this but I've just found out that
print implode("<br>", $_SERVER);
Gives the warning :
Notice: Array to string conversion in c:\phpdev\www...
Doesn't do it...
|
by: DJ Craig |
last post by:
I have 2-dimensional array with numeric indices for both dimensions,
called $results, which contains the search results from a database.
The first dimension contains the records, and the second...
|
by: guitarromantic |
last post by:
Hey everyone,
I run a site with staff-submitted reviews, and most of them are written
by one author. However, we also do "multiple" reviews. Up until now I
just had a userid for a 'Multiple'...
|
by: rbragg |
last post by:
All of my other form data is stored correctly in the db except for my checkbox data. This column in my table is empty.
I have this checkbox group on my form:
<input name="cbItems"...
|
by: NoWhereMan |
last post by:
Maybe a stupid question.
-------------------------
1
-------------------------
$str = '';
for($i=0; $i<10; $i++)
$str .= $i;
|
by: atyndall |
last post by:
OK, this is the relevant portion script:
<?php
$username = '__'; // MySQL Database Username.
$password = '__'; // MySQL Database Password.
$server = '__'; // MySQL Database server (most...
|
by: Immortal Nephi |
last post by:
I would like to design an object using class. How can this class
contain 10 member functions. Put 10 member functions into member
function pointer array.
One member function uses switch to call...
|
by: BryanA |
last post by:
I'm not quite sure which function to use when I want to add a comma to
the end of every line and a semi colon to the last one. Because it
generates everything on the fly I can't count the rows from...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |