Solved

Date Format Win32::ODBC Ms Accesss

Posted on 2003-10-22
7
346 Views
Last Modified: 2010-03-04
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
Comment
Question by:baz_can_fix_it
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 5

Accepted Solution

by:
fantasy1001 earned 20 total points
ID: 9605847
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
 
LVL 1

Author Comment

by:baz_can_fix_it
ID: 9611106
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
 
LVL 1

Author Comment

by:baz_can_fix_it
ID: 9611420
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Expert Comment

by:jmcg
ID: 9611664
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
 
LVL 1

Author Comment

by:baz_can_fix_it
ID: 9611710
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
 
LVL 20

Expert Comment

by:jmcg
ID: 9611744
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
 
LVL 1

Author Comment

by:baz_can_fix_it
ID: 9611783
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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question