Solved

Date Format Win32::ODBC Ms Accesss

Posted on 2003-10-22
7
325 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 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now