I assume you're using Drupal 6. See the date_api.module functions like date_make_date() which will return a Date object that can be formatted with date_format_date().
After all search, I found it really difficult to deal with date. I am trying to store the date in MySql table as varchar type and placeholder as %s.However I need two functions to convert date from array format to string format (required while storing into table) and string format to array format (Required while showing it in form).The below code does that for me.function dateArrToStr(&$customDateArr)
{
$strDate = t($customDateArr['day']).t('- ').t($customDateArr['month']).t('-') . t($customDateArr['year']);
return $strDate;
}function dateStrToArr (&$customDateStr, $length)
{
$convDate = array();
$index = 0;
$customToken = t('');
$dashPosition = 0;
for($index = 0; $index < $length; $index++)
{
if($customDateStr[$index] == t('-'))
{
if($dashPosition == 0)
{
//Set the day
$dashPosition++;
$convDate['day'] = $customToken;
}
else if ($dashPosition == 1)
{
//Set the month
$dashPosition++;
$convDate['month'] = $customToken;
}
$customToken = t('');
}
else
{
$customToken = t($customToken) . t($customDateStr[$index]) ;
}
}
//Set year
$convDate['year'] = $customToken;
return $convDate;
}RegardsAustinOn Mon, Mar 28, 2011 at 8:36 AM, Austin Einter <austin.einter@gmail.com> wrote:
Hi AllI have a date field in my form.How do I store/retreive the value into/from MySQL.On google search, I saw people are suggesting to use either "int" or "datetime" type.Please suggest which one needs to be used.If I use int (I hope core uses int), while storing can I just store "form['values']['date1']" as %d and while retreivin, what are the related apis to convert back to date.RegardsAustin.
--
[ Drupal support list | http://lists.drupal.org/ ]