sun14php Posted June 29, 2006 Share Posted June 29, 2006 what should i do for following results ?1. I want to enter date in textbox(form html/php) in dd-mm-yy format2. the above date i enter in dd-mm-yy format should be stored in mysql date column either in yyyy-mm-dd or dd-mm-yy format.3. date stored in mysql column should be displayed in browser in dd-mm-yy fromat.i think i worte so simple. if yes help me out.thanx a lot Link to comment https://forums.phpfreaks.com/topic/13182-confusing-dates-time/ Share on other sites More sharing options...
heckenschutze Posted June 29, 2006 Share Posted June 29, 2006 I shall make a start for you...[b]Note: You will need to add validation and error checking, this serves as example only.[/b]Adding:[code]<?php$strDate = $_POST["my_date_box"];$arrayDate = explode("-", $strDate);$intTimestamp = mktime(0, 0, 0, $arrayDate[1], $arrayDate[0], $arrayDate[2]);//** add timestamp to a MySQL.int column?>[/code]We split the string up, and turn it into a UNIX-timestamp (using mktime()), this way we can manage it easier.Displaing[code]<?php$intTimestamp = 0; // The timestamp from your MySQL.int columnecho date("d-m-y", $intTimestamp);?>[/code]After getting the timestamp from your SQL db, we can manage how it is displayed by using the date() function.hth, Zac. Link to comment https://forums.phpfreaks.com/topic/13182-confusing-dates-time/#findComment-50720 Share on other sites More sharing options...
sun14php Posted June 29, 2006 Author Share Posted June 29, 2006 i used ur code but instead of storing 02-06-06 it's storing 0000-00-00 in mysql database. why ?in browser it's showing : 30-11-1999& what is the meaning of the line: //** add timestamp to a MySQL.int column Link to comment https://forums.phpfreaks.com/topic/13182-confusing-dates-time/#findComment-50743 Share on other sites More sharing options...
redarrow Posted June 29, 2006 Share Posted June 29, 2006 [!--quoteo(post=389173:date=Jun 29 2006, 09:26 AM:name=sun14php)--][div class=\'quotetop\']QUOTE(sun14php @ Jun 29 2006, 09:26 AM) [snapback]389173[/snapback][/div][div class=\'quotemain\'][!--quotec--]i used ur code but instead of storing 02-06-06 it's storing 0000-00-00 in mysql database. why ?in browser it's showing : 30-11-1999& what is the meaning of the line: //** add timestamp to a MySQL.int column[/quote]$date=("dmy");input name="date" Link to comment https://forums.phpfreaks.com/topic/13182-confusing-dates-time/#findComment-50744 Share on other sites More sharing options...
sun14php Posted June 29, 2006 Author Share Posted June 29, 2006 [!--quoteo(post=389174:date=Jun 29 2006, 04:31 AM:name=redarrow)--][div class=\'quotetop\']QUOTE(redarrow @ Jun 29 2006, 04:31 AM) [snapback]389174[/snapback][/div][div class=\'quotemain\'][!--quotec--]$date=("dmy");input name="date"[/quote]this code didn't help too. Link to comment https://forums.phpfreaks.com/topic/13182-confusing-dates-time/#findComment-50758 Share on other sites More sharing options...
obsidian Posted June 29, 2006 Share Posted June 29, 2006 [!--quoteo(post=389188:date=Jun 29 2006, 06:23 AM:name=sun14php)--][div class=\'quotetop\']QUOTE(sun14php @ Jun 29 2006, 06:23 AM) [snapback]389188[/snapback][/div][div class=\'quotemain\'][!--quotec--]this code didn't help too.[/quote]according to your initial question, you're storing the date in the database as a DATE datatype, not an integer, so you'll need to format it as such. try something like this (and, as mentioned above, you'll have to work some error checking, as this just shows the principle:[code]// make sure that the user date is in DD-MM-YYYY format firstlist($day, $month, $year) = explode("-", $_POST['userDate']);$insertDate = "$year-$month-$day"; // insert this value into your table// now, once you pull it back out of your table, just display it like this$sql = mysql_query("SELECT * FROM tableName");while ($x = mysql_fetch_array($sql)) { $date = date('d-m-Y', strtotime($x['dateColumn'])); echo "$date<br />\n";}[/code]good luck Link to comment https://forums.phpfreaks.com/topic/13182-confusing-dates-time/#findComment-50796 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.