Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Date Format When Inserting Data


I am getting a date entry through POST by a form byt the format enetered by the user is 'dd/mm/yy' .... how could i use MYSQL PHP syntax to insert the proper format as it is default in the table in my database. which function is it?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Converting A Date Format (dd/mm/yyyy) Into A Time() Format
I want to convert a date in the format (dd/mm/yyyy) into a time() style format so I can compare it against the current time and only use information where its date is ahead of the current time.

Format A Number For Inserting Into Db
If a user enters a number with a comma in it say 11,000.70 how do I strip out the comma to insert it correctly?

Problems With Reading Data From A Text File And Inserting The Data Into DB
Ive been having problems getting this to work for 3 days now. Basically what im trying to do is read from a text file and insert the information into mysql. The text file is in this format:

"LuCyndi@infiniti.com","carol","kellerhals","109 veeder dr","las vegas","NV","89128","702-254-2061","45"
"the_prophet@att.net","a.","cohen","6794 e. bonanza rd","las vegas","NV","89110","702-463-6569","55"

I understand how to open files to read but im having problems turning each set of data into an array so i may insert it into mysql. If someone could please help it would be appreciated.

Inserting Date Into Database
I have a pretty simple news code that inserts the data, and then is retreaved, with a pretty simple scheme. I have a date column set at timestamp(14), and I'm trying to insert NOW() as the date. I browse with phpmyadmin and all it has is 14 zero's. PHP Code:

Inserting Date & Time
I am using now(), but I'd like to use strftime("%d. %B %Y %R"). I can't for the life of me figure out how to use strftime("%d. %B %Y %R") in the code below without it failing.

The other issue is that both now() and strftime("%d. %B %Y %R") return 9/27 as the date. But it's 9/28.  How can get it to return the correct date? I thought the setlocale would address this. Code:

Inserting Date In Database
I have form which allows a user to select a date as part of the form.
On submitting i am getting no update to the database and no error message.
To try and test it i created a shorter version which sets up the variables except the date.This gives the same result.ie no update. Code:

Date Format ...
I have dates with this format

1 9 99 00:00:00

I want to transform it in yyyy-mm-dd

how can I do with php ?

Help On Date Format
I have this page where user select month day and year from a drop down list and when the user pass it to selectdate2.php
it will be as treated one variable in a date format yyyy-mm-dd. any suggestion?

this is the first page named selectdate.php

<select size="1" name="month">
<option>01</option>
<option>12</option>
</select>
<select size="1" name="day">
<option>01</option>
<option>31</option>
</select>
<select size="1" name="year">
<option>2000</option>
<option>2003</option>
</select>

Date Format
I have a script running (with great effort and help from the group) that displays a date from a database and the amount of days to that date.

I would like to change the date into a more "human" format. The date now displays:

2002-12-08

I would like to change it to:

Sunday, December 08th

Is this a property of mktime()?

Date Format
Can a guru show me the equivalent of this code (that I use in Mysql), but need to replicate in MSSQL....

[MySQL CODE]
Date_format(Orderdate, '%y-%m') as period .... more statements
[/MySQL CODE]

How do I do this in MSSQL? The date is in this format in MSSQL DB.: 2003-11-30 00:00:00

**I have tried various things but my efforts are failing!

Date Format
I have a date in dd/mm/yyyy format i.e. 15/03/2007 The problem is that when I am storing this in MySql it uses yyyy/mm/dd format so the value stored in the DB ends up being 2015-03-20 Does anyone know how I can get around this problem?

Date Format
I can't figure out why the date did not came out correctly.

I wrote
Quote<?php
$b = "2006-03-01";
print date("m/d/y",$b);
?>

It suppose to come out as 01/Mar/06. But what what came out was 01/Jan/70. 
Can anyone tell me why this happens.

Date Format
if i have a date stored in my DB as 11/09/2007

is there anyway i can change it to 11th Sep once i have pulled it from the DB?

Inserting Current Time/date.
I am trying to insert the current date/time into a MySQL table field when a record is inserted, however i cannot get it to work. My PHP is basically like this:-

$sql = "INSERT INTO Table (ref,title,first,surname,telephone,mobile,ila,ila_date,status)
VALUES ('$ref','$title','$first','$surname','$telephone','$mobile','$ila','NOW()','$status')";

The field called "ila_date" is where i want to add the current date/time. Ive read about the NOW() function, but i think im useing it incorrectly. My MySQL table column "ila_date" is of type timestamp(14).

Time/Date Format
I'm pretty sure there is a way to do this, but I don't know what the code is to do what I'm trying to get.

Is there a way to get the current date and time in YYYYMMDDHHNNSS format (as an example, 20001030111100)? I would guess you can but I don't know what the code is.

Date Format Function Gone Bad
I am trying to clean up a DATETIME value from a Mysql database for presentation. So I am using the following basic function right out of devsheds recent article:

function cleanDate($val)
{
$arr = explode ("-", $val);
return date("M d, Y", mktime(0,0,0, $arg[1], $arg[2], $arg[0]));
}

Then feeding it a Mysql like DATETIME value for a test and echoing it to he page. Also I have added a current date echo to ensure that "it" knows that much.

$date = "2002-03-18 11:19:57";
echo "Updated " .cleanDate($date);
echo "<br>Todays date: " .date("F d, Y", mktime());

and here's my output....

Updated Dec 31, 1969
Todays date: March 20, 2002

Where have I gone wrong?

Date Format From MySQL In PHP
I've recently been successful in converting the MySQL date format YYYY-MM-DD to DD-MM-YYYY, but does anyone know of a way to actually format it so that it displays the corresponding months?

eg. 25-10-2003 = 25 Oct 2003

Convert A Date Format
I am displaying records from a table including a stored date. When
display $row[Date], i get the obvious 2006-05-21. However this is not
what the guy wants. He wants 21-May-2006.

I have tried several conversion functions but without success. I could
do a long winded function, but i hoped there would be a simple
solution.

MySQL / PHP Date Format
I am using php to call info from a mysql database. My date comes in format yyyy-mm-dd but I want it in dd-mm-yyyy. I know I need to use something like:

SELECT DATE FORMAT (date, %d-%m-%y)

But I'm not sure how to include it in my query which is also calling other items from the database:

$result1 = mysql_query("SELECT * FROM practice AS p, project AS t, regions AS r, gpcats AS c WHERE p.id = t.id AND t.region = r.region AND p.gpid = c.gpid AND gptext LIKE '%$search%' AND $region=0 AND '$cat'=&#390;'GROUP BY p.gpid ORDER BY verified DESC"

SQL Statement With DATE Format
i want to compare dates. The dates are like "2007-06-25".
I tried this:
$SQLString = "SELECT * FROM myDB.myTABLE WHERE dat_start = $act_dat";
But it didn't work.
What can I do?

Changing Date Format
If I fetch a date from a mysql field and the date is: 2006-01-12 00:00:00

Is there a way I can reformat it in php to lose the hr.min.sec so that I am just left with the date 2006-01-12??

Displaying The Date In A Different Format!
I have a row called Date in the databse which is saved as 0000-00-00 When I try to echo it, it shows like that 2007-04-16 Maybe because I use this normal code: echo $row['Date']; How can I display it like that:16-04-2007

Change Date Format
I would like to know how to change the date format in 31-JUL-2007 to 07-31-2007?

Changing Date Format
i hve a date variable in mm-dd-yyyy format how can i change it to mysql default format i.e., yyyy-mm-dd format ...

From Varchar To Date Format
i am having one problem with mysql.Previously i have created one Date field as varchar format.Now i want change that field as date fromat and also the data should be there as date format whatever i have stored previously.

Searchable Date Format
Whats the best searchable date format for php mysql ? Im after only showing news on and after the publish date specified.

So i first need to know which date() i should be using..

Iv researched date() and got date("Y-m-d"); , but is this searchable?

Also would need to know how to show only articles that have todays date or previous dates ( not future dates etc ).

Inserting A Date Into A Microsoft Access 97 Database
I was wondering if anyone could help me insert a short date into microsoft access 97 using php? i can insert text no problem but i can't seem to be able to insert a date properly. i have been using

//$date = "#" . "$sqlmonth" . "1" . "$cboyear" . "#";

$strSQL = "INSERT INTO tblSupport (tDate) VALUES ($date)";
$result = odbc_exec($connect, $strSQL);

Note: i can insert a date if i hard code it like putting in #01

How To Manupulate MySQL Date Format In PHP?
MySQL date format is yyyy-dd-mm. how can i make full manupulation of the date with php? For example, how can i make the date to 29-september-2002 and others manupulation.

Date Validation YYYY-MM-DD Format
Hi, I am using forms which input dates into a mysql table, these work fine. However I would like to validate these into the correct format which is YYYY-MM-DD. So I am guessing I need an ereg function which looks for a string of 4 followed by a dash, then 2 then a dash and finally two more.
The code I have so far is:

$date_pattern = "([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})";
if (!preg_match($date_pattern,$EventStart))
{
echo ("<br>Wrong date format");
$FormValid="False";
}

MySql Query, Php Date Format.
This is actually 2 questions, but they go to gethere so I'm asking them as one. First, how do I write a MySql query that returns all the rows that have a date in the date collum that is newer than todays date? Then I need to take those rows, format the date in them and then print them in a table.

Always Local Time & Date Format?
Is there a script available that would re-format a time & date always
according to the users' setting?

Some setting that would be read by the language set in the browser or from
the IP?

MySQL > Timestamp > Date Format
i know that MySQL uses the unix timestamp thing, and i can display the date by doing this
PHP Code:

Date Stored In DB In The Following Format: 2004-06-29 09:06:36+01
I am trying to convert a date in the following format with the date
function (i.e. date("d/m/y", strtotime($dbdate));):

2004-06-29 09:06:36+01

The database was created by another programmer as I normally store my
dates as datetime type in the format:

2005-07-08 10:52:44

What Is The Proper Date Format For A Txt Database?
I would like to know what format should be used when writing to a txt file. I am trying to search between a start date and a ending date and list any variables For example.

if (($sDate <= $jdate && $eDate >= $jdate))

then I have it list the variables it will work if searching between months and days but it does not work if I have different years. I will get all years printed out.

my date format is m/d/Y 6/13/2001

If I search for example start date = 6/01/2001 and the ending date = 6/09/2001

I will get the correct month and day dates but I also get anything from the year before and including year in the future.

PHP Date Conversion To Readable Format
i have FPDF (php script that generates pdf files from variables). I can get the from date and to date to show, but they show like this: e.g.: 2006-12-20
now im trying to do this but its not working: Code:

Date & Time Format In Database.
I'm using MySQL database, the problem is I've setup that user input the Date format in dd/mm/yyyy (example: 14may2007) and Time (example: 12:00pm). How do I convert it to Date & Time format in database format before insert into database? Sorry, noob here.

Date Format In Join Statement?
$get_matches=mysql_query("SELECT matches.match_id, matches.game, matches.opponent, matches.map, DATE_FORMAT(`matches.date`, '%d/%c/%y') AS 'matches.date', matches.time, players.player_id, players.match_id FROM matches, players WHERE matches.match_id = players.match_id AND players.player_id='$player_id' AND matches.game='$game'") OR die(' ERROR GETTING TOTAL $game MATCHES ' . mysql_error());

Basically I'm trying to format a date column from the american style date format into the european one, but for some reason its not working. I've got it working in non join statements but I don't know how to do it in a join statement.

Date Format / Timestamp Problem
I am facing one problem in php, mysql whenever i submit empty date to db, it automatically takes timestamp as 943900200 ('30-11-1999') which is creating problems in my application..... currently handling this problem by hard coding timestamp validation.

Dates And European Date Format
ATM my database is using an American style date format with the year coming first, then the month then the day, is there a way to set it so it goes day, month, year?

Basically how it works is I got 3 drop down boxes with days, months and years in it. The user choose the desired date clicks a button and it updates the db. My problem is its has that American format and if I put it as text then I won't be able to do calculations or sorts on the date so I need it as a date.

Also do I need to actually change anything in my mysql data base in regards to the date field atm I got it set as a date is there any additional things I gotta change?

Inserting Data Into A Row
I’ve got a table of three fields (id, name and comments) that contain 30 rows. Each row contains data in the two first fields (an id and a name). The third filed is empty.

When a user accesses my page they can select one of 30 names from a drop down menu. After they’ve selected a name the user can write a comment about the person he/she selected.

How can I insert the comment from the user into the comment field related to the name selected?

Inserting Data Twice
I'm working with a database now, and I have an error here, somewhere. The first time the user hits submit, the data goes in once, the second time the user hits submit, the data goes in twice. I don't know why. PHP Code:

Inserting Data
how to insert select and view data from a database but i cant get it to work, it says that the data has been insterted but when i go to index.php nothing is shown, maybe it is my database? wht should the code be to make a suitable database? Code:

Inserting Data Only ONCE
I currently have the following:

$zip = $db->escape($_GET['zip']);

$db->query("INSERT INTO zipdata SET zips = '$zip'");
However, every time that page loads it is inserted. Is there a way to make it only insert one time per user.

Displaying Local Date In Specific Format
i'm trying to decide whether to use PHP or JavaScript to display a date on a website. what i'm wondering is where does PHP take the date from, the server or the client (ie will timezone become a factor). aswell as this, is there a simple way to allow the date to be displayed as: "22nd" "1st" or "14th" instead of "22" "1" or "14"?

Output Format For A Timestamp Date Variable
I have a variable - $lastdate - that is the latest date any record in a
MySQL database was updated. Its MySQL format is TIMESTAMP.

If I say [echo $lastdate] I get the output I'd expect - 20060424221549
which is a YYYYMMDDHHMMSS format.

I'd like to be able to display that using a format of mm/dd/yy with no
leading spaces on the month and day. I don't know what the php command
is to do this. In other words, I'm trying to display a variable -
$lastdate - formatted a certain way. I know that the formatting string
n/j/y will get my output looking as I'd like, but I can't figure out how
to apply that to my variable.

Inserting Data Into A Table
I would like to know if there is anything strange about the script below(I have only just started to learn php so there may well be!)
Although it seems to work, occasionally it doesn't just insert a single row into the data base, instead 2 or 3 duplicate rows end up in the table. Could the explanation be that I tried this morning to create a table and forgot I already had one with this table name in the database. Would that have damaged the table in some way making it misbehave!
I have commented out the bit about creating tables as I only want to insert data with this script at the moment. One other thought occurs to me, is the problem due to my host freedom to surf as its only a free host and I expect you get what you pay for(or don't pay for in this case). I have subscribed to a pay host http://www.phpwebhosting.com but I am unable to use the database that they have provided because they have informed me that I must use a telnet shell to log into my database and I have absolutly no idea what this is(is it in my Win98?) or do I need to go and get one. I am still waiting for this host to email me back with some help. If there is anyone out there who could tackle all or some of my problems I would be very grateful indeed!
One last thought - I think there is something very strange going on as sometimes when I visit my database, there is less entries in this table than last time, some have been chucked away and my id entries are all out of order now, something like 1,2,3,11,5,7,12 - the last insert had id = 12 next to it and somehow another duplicate has sprung up id = 11????????
Whats going on please!

<html>
<head>
<title> Connecting to Mysql server at ISP host</title>
</head>
<body>
<?php
$Host = "db.davegraham.f2s.com:3306";// Set the variables for the database access:
$User = "p0c79";
$Password = "********";
$DBName = "p0c79";
$TableName = "Jokes2";

$link = @mysql_connect("$Host", "$User", "$Password");
if (!$link)
{
print("<P>Unable to connect to the " .
"database server at this time.</P>
"); //note how 2 strings have been concatonated
exit();
}
else
{
print("Your now connected to the Mysql server at the host ISP.<P>
");
}

if (! @mysql_select_db("$DBName") )
{
print("<P>Unable to locate the $DBName database at this time.</P>
");
exit();
}
else
{
print("The database $DBName has been located.</P>
");
}
/*
$sql = "CREATE TABLE $TableName (ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, JokeText TEXT, JokeDate DATE NOT NULL )";
if ( mysql_query($sql) )
{
print("<P>$TableName table successfully created!</P>
");
}
else
{
echo("<P>Error creating $TableName table: " .
mysql_error() . "</P>");
}
*/

$Query="INSERT into $TableName VALUES(&#390;', 'hello hello hello!', &#55614;&#57152;-08-08')";

if (mysql_query ($Query))
{
print ("The query was successfully executed!<br>
");
}
else
{
print ("The query could not be executed!<br>
");
}
mysql_close($link);
?>
</body>
</html>

Inserting Data Using A Form
I created a script to allow the user to select the number of images to enter. After that the script generates the entry fields dynamically. The final step is entering all images into one column in the db called images.
The problem is i got it to work using an advice from someone at devshed forums to use some additonal script. Please see below.

1) HTML File that allows you to enter the number of text boxes to create for each image you want.


<FORM METHOD="POST" ACTION="do_show.php">
<P><strong>Number of images:</strong><br>
<INPUT TYPE="text" NAME="num_imgs" SIZE=5></p>
<P><INPUT TYPE="submit" NAME="submit" VALUE="Go to Step 2"></p>
</FORM>

2) PHP file that shows the created text boxes for you to enter the names of these images:

Inserting Data Into 2 Tables
I've got this products page form and what I have is two tables to insert the data into, about_products,about_urls.

What I am trying to achieve is to insert info into about_products table and the URLs associated for that product. The thing is, is that I'm having trouble getting to insert the URLs for that product. Note that the product form is duplicated 8 times. PHP Code:

Inserting Data Into A Table.
I keep getting a parse error with this code. What am I doing wrong? The SQL statement works in MySQL. Is there something wrong w/the way I'm decaring my PHP variables? Code:


Copyright © 2005-08 www.BigResource.com, All rights reserved