...

View Full Version : Why Is My Date Not Being Display Correctly?



Byronwells
02-02-2010, 01:32 AM
Alright guys

I am wondering why is the date not be displayed properly on this page please http://www.digitalresellersvault.com/marketplace.php?cat=t&category=Private_Label_Rights

Let me start from the top

I have added a javascript date picker, and text box to the add products.html page.. Here is the code for that bit



<input type="text" name="product_date" value="{{product_date}}" id="date" size="20" />
<script>
$('#date').datepicker();
</script>


I know that bit works because it allows me to select whatever date I want and then it is showed in the text box..

I have then linked that text box to a field on a mysql database called product_date using these two pieces of code. The field is in date format



$product_date = $_POST["product_date"];
$set .= "product_date = '$product_date',";


The marketplace.php is used for the layout of the site.. The following code tells the page what to load up



$GetFile = file("http://www.digitalresellersvault.com/template/template.php");
$Content = join("", $GetFile);
$categories=$common->categories($db);
$content=str_replace("{categories}",$categories,$content);
$Pat = "/<{Begin}>(.*?)<{End}>/s";
preg_match($Pat,$Content,$Output);
$SelectedContent = $Output[1];
$q = "select * from ".$prefix."products where show_product = '1' ORDER BY Rand() LIMIT 1";
$r = $db->get_a_line($q);
$id = $r[id];
$imageurl = $r[imageurl];
$prod_description = $r[prod_description];
$salesprice = $r[price];
$product_name = $r[product_name];
$licence = $r[licence];
$product_date = $r[product_date];
$salespage_link='<a href="prods.php?pid='.$id.'"><img border="0" src="http://www.digitalresellersvault.com/template/images/moreinfobutton.jpg" width="104" height="16"></a>';


As stated before I can choose and date and then stored in on the database.. But for some reason I can not get the date to be displayed.. I can only get the 0000-00-00 to display..

I am a little bit confused

Len Whistler
02-02-2010, 02:32 AM
As stated before I can choose and date and then stored in on the database.. But for some reason I can not get the date to be displayed.. I can only get the 0000-00-00 to display..

I am a little bit confused

What value is in the DB? When I get 0000-00-00 it was because the INSERT query was wrong for the date column and I ended up with 0000-00-00 inserted into the DB.



-----------

Byronwells
02-02-2010, 04:36 AM
What value is in the DB? When I get 0000-00-00 it was because the INSERT query was wrong for the date column and I ended up with 0000-00-00 inserted into the DB.



-----------

What do you mean value?? All I did was create a field called it product_date, chose the date type and that is it..

What else am I suppose to do?

Len Whistler
02-02-2010, 06:19 AM
What do you mean value?? All I did was create a field called it product_date, chose the date type and that is it..

What else am I suppose to do?

What does the date look like in the date column? If you enter February 1, 2010 it will end up like 0000-00-00. It must be entered as YYYY-MM-DD.


------

langdon4487
02-02-2010, 09:59 AM
Hi.. Byronwells.

You can try with the different date function to solve out your problem.
Another reason may be your system Date/time is not correctly set so it may saw you wrong date.


-------------------------------

ClickSSL.com (http://www.clickssl.com/)

Byronwells
02-02-2010, 02:34 PM
What does the date look like in the date column? If you enter February 1, 2010 it will end up like 0000-00-00. It must be entered as YYYY-MM-DD.


------

Len oh right.. I used the defualt setting, which is 0000-00-00 :) I didnt realised that I could change it the db field :)

Byronwells
02-02-2010, 02:52 PM
Hi.. Byronwells.

You can try with the different date function to solve out your problem.
Another reason may be your system Date/time is not correctly set so it may saw you wrong date.


-------------------------------

ClickSSL.com (http://www.clickssl.com/)

The date is stored in the text box like this

02/15/2010 0 MM-DD-YYYY

I have attempted to change the product_date vaule field to that format.. But it still displays the 0000-00-00 format even in the db field and on the site.. I have deleted the field and start fresh, and it stil does the same...

Do I need some code like this?
$_POST['date'] = date('Y-m-d', strtotime($_POST['date']));"

Byronwells
02-02-2010, 02:55 PM
Hi.. Byronwells.

You can try with the different date function to solve out your problem.
Another reason may be your system Date/time is not correctly set so it may saw you wrong date.


-------------------------------

ClickSSL.com (http://www.clickssl.com/)

Alright Langdon

I am trying at the moment to play around with different date functions. I have attempted to change the vaule of the product_date to read mm-dd-year, but it still displaying in 0000-00-00

Len Whistler
02-02-2010, 06:44 PM
The date is stored in the text box like this

02/15/2010 0 MM-DD-YYYY


The mysql date must be entered as YYYY-MM-DD, otherwise you end up with 0000-00-00. You will need to create a PHP function to format the input properly.



----------

Byronwells
02-02-2010, 06:54 PM
The mysql date must be entered as YYYY-MM-DD, otherwise you end up with 0000-00-00. You will need to create a PHP function to format the input properly.



----------

Len

I have got the numerical date to appear now.. see here...
http://www.digitalresellersvault.com/marketplace.php?cat=t&category=Dec_2008

What I am about to attempt now is to take the month numerical date and turn it words.. i.e dec/02/2010

Len Whistler
02-02-2010, 07:03 PM
This will take a mysql date column.

$formattedDate = date("F d, Y g:i a",strtotime($row["time_stamp"]));

And output this:

January 02, 2010 4:02 pm EST




---------

Byronwells
02-02-2010, 08:41 PM
This will take a mysql date column.

$formattedDate = date("F d, Y g:i a",strtotime($row["time_stamp"]));

And output this:

January 02, 2010 4:02 pm EST




---------

Len

If I am using the product_date field.. how do I GET the adove code to be linked to that one please??

And thank you for your help :)

Len Whistler
02-02-2010, 10:08 PM
With a msql query. Untested, might be syntax errors.


$sql = mysql_query("SELECT * FROM db_table_name");

while($row = mysql_fetch_array($sql)){
$formattedDate = date("F d, Y g:i a",strtotime($row["date_column"]));
echo "$formattedDate";
// echo other mysql data
}



----

Byronwells
02-03-2010, 01:51 AM
This will take a mysql date column.

$formattedDate = date("F d, Y g:i a",strtotime($row["time_stamp"]));

And output this:

January 02, 2010 4:02 pm EST




---------

Len

I do apologise for being a pain :)

I have been told by someone that I need to put the following code in the add_products.php

"With regards to the 0000-00-00 check that the date being sent to the server is in the correct format. To be safe, it should be in the format 'Y-m-d'. You can use something like "$_POST['date'] = date('Y-m-d', strtotime($_POST['date']));" where 'date' is the name of the date input element."

But I am not sure exactly where...

sslcertificates
11-23-2010, 01:05 PM
There is a WordPress knowledge base file that explains all the different date format types.

http://codex.wordpress.org/Formatting_Date_and_Time

which to me explains all the varying date formats perfectly.

-------------------------------

SSL Certs (http://www.ssl247.com)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum