Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Date Format Win32::ODBC Ms Accesss

Posted on 2003-10-22
7
Medium Priority
?
363 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
  • 4
  • 2
7 Comments
 
LVL 5

Accepted Solution

by:
fantasy1001 earned 60 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
Independent Software Vendors: 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

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!

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Six Sigma Control Plans

926 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