• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 367
  • Last Modified:

Date Format Win32::ODBC Ms Accesss

Hi experts

this should be very easy :) I am using Win32::ODBC to connect to an access DB I am having problems getting the right format for date I keep getting it in this format 2003-09-21 00:00:00 and I want it to be shown as this 09-21-2003 without changing anything in MS Accsses... Cheers

Thank you in advance


use Win32::ODBC;
#####$ODBCDate = sprintf("{d '%d-%d-%d'}", , $day,$mon,$year);
my $db = new Win32::ODBC("DSN=blah");
my $statement= "SELECT *FROM blahblah";
if($db->Sql($statement))
      {
      my $errortext=$db->Error();
      # error-handling code here
      $db->Close();
      exit
      }
while ($db->FetchRow())
      {
      %Records = $db->DataHash();
      $tablebody .= "<tr>";
      $tablebody .= "<td nowrap>&nbsp;".$Records{"Date"}."</td>";
      $tablebody .= "<tr>"
      }
$db->Close();

#result screen
print <<EOF ;
Content-type: text/html

<html>
<head>

</head>
<body bgcolor="#FFFFCC" link="#660000" vlink="#660000" text="#000066">
<Center>
<p><font size="4" color="#000066">Blah</p>
<table border="1" bordercolor="#000066">
<tr>
  <th>Date</th>
</tr>
  $tablebody
</table>
</body>
</html>
EOF

0
baz_can_fix_it
Asked:
baz_can_fix_it
  • 4
  • 2
1 Solution
 
fantasy1001Commented:
Put simple:
you want to change 2003-09-21 00:00:00 to 09-21-2003

$temp = split / /, $Records{"Date"};
my($year, $month, $day) = split /-/, $temp;

$temp = join "-", $month, $day, $year;

Thanks & cheers
0
 
baz_can_fix_itAuthor Commented:
Hi fantasy1001

That gives me now  --2 as date... any ideas?  here is what i did

while ($db->FetchRow())
      {
      %Records = $db->DataHash();
      $temp = split / /, $Records{"Date"};
      my($year, $month, $day) = split /-/, $temp;
      $temp = join "-", $month, $day, $year;

      $tablebody .= "<tr>";
      $tablebody .= "<td nowrap>&nbsp;$temp</td>";

Cheers
0
 
baz_can_fix_itAuthor Commented:
Hi fantasy1001

Don't worry thanx for trying I have fix the problem my self...Here is how...Cheers

my($year,$month,$day ) = split ('[/.-]', $Records{"Date"});
my($d,$hr,$min,$sec) = split ('[/ :/]', $day);
$tablebody .= "<td nowrap>&nbsp;$d/$month/$year</td>";
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
jmcgOwnerCommented:
Fantasy should have said:

   my ( $temp) = split / /, $Records{Date};

by leaving out the parens, split returns a count rather than the results of the split.

==========

If you don't like what he showed you and you found your own solution, you are within your rights to request a points refund in Community Support (now it's that CS tab on the far right of that menu bar that appears in the "new" look for Experts Exchange).
0
 
baz_can_fix_itAuthor Commented:
Hi jmcg

Thanx for that...How do i split the points 10 for you and 10 for fantsy1001...there use to be a split option like assisted answer...this new look is confusing me :)
0
 
jmcgOwnerCommented:
I'm still reserving judgement on the new look. There have been a few improvements since it was first introduced.

If you don't have a split points button, it may be because you are not allowed to split at 20-point question. The powers-that-be do not want to see less than 20 points awarded, which limits how fine your splits can be.

If you have limited points, ask for a refund. You'll be able to ask another question with them. If you feel like you have plenty of points, go ahead and accept Fantasy's answer. He was first on the scene and gave you something that was real close to working.

0
 
baz_can_fix_itAuthor Commented:
Thank you both...

Ye i must admit the look is getting better and better every day...sometimes the "your status" table would go a meter to the right side :) lol....But you all doing an excellent job and this is the best place on the net...

Cheers

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now