INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

POSIX::strftime

POSIX::strftime

(OP)
Hi

I am trying to configure a Bug Tracking program that is written in Perl and want to get the dates to format differently.

These are the lines of code in one of the PERL Modules that I want to change...


sub now {
   
    my $now = POSIX::strftime("%Y-%m-%d %H:%M:%S", localtime);

    return $now;
}


What I want to return is a date in the format of (dd-mm-yyyy)..


   my $now = POSIX::strftime("%d-%m-%Y %H:%M:%S", localtime);


But this just fails.  Can anyone help?

RE: POSIX::strftime

What do you mean by "just fails"? Your code worked perfectly for me.

$ perl -MPOSIX -e 'print POSIX::strftime("%d-%m-%Y %H:%M:%S", localtime),"\n"'

03-02-2004 11:21:07

RE: POSIX::strftime

Try this instead of using POSIX functions


(@date)=localtime;
$date[5]+=1900;$date[4]++;
$now=sprintf("%0.2d-%0.2d-%0.4d %0.2d:%0.2d:%0.2d",$date[3],$date[4]++, $date[5], $date[2],$date[1],$date[0]);
print "$now";


HTH
--Paul

RE: POSIX::strftime

(OP)
When I try

sub now {
   
   my $now = POSIX::strftime("%d-%m-%Y %H:%M:%S", localtime);

    return $now;
}


All i get is.......

CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:


DBD::ODBC::st execute failed: [Microsoft][ODBC SQL Server Driver]Invalid character value for cast specification (SQL-22018)(DBD: st_execute/SQLExecute err=-1) at lib/dbase.pm line 78.
DBD::ODBC::st execute failed: [Microsoft][ODBC SQL Server Driver]Invalid character value for cast specification (SQL-22018)(DBD: st_execute/SQLExecute err=-1) at lib/dbase.pm line 78.

RE: POSIX::strftime

Looks like you've an SQL error at line 78.

RE: POSIX::strftime

(OP)
I don't see why ....

This will work:

my $now = POSIX::strftime("%Y-%m-%d %H:%M:%S", localtime);

But this throws an error!

my $now = POSIX::strftime("%d-%m-%Y %H:%M:%S", localtime);

RE: POSIX::strftime

I would guess that you're using $now to insert into the database, but it's not in a date format that your SQL server understands.

RE: POSIX::strftime

(OP)
So how do I configure SQL Server to understand my date format?

RE: POSIX::strftime

(OP)
The Language settings on the Database Server are set to English (United States).  This is probably the reason why I am getting this error, as rosenk has suggested.

Unfortunately, I cannot verify this by testing it as I cannot reboot the server.

RE: POSIX::strftime

Most (if not all) SQL DBs behave like that, i.e. accepting dates in yyyy-mm-dd format. This is because of the ambiguities involved in doing it any other way, for example 02/03/2004 is the second of March in Europe, while it's the third of February in the US. The yyyy-mm-dd format is the international standard for representing dates, since nobody would agree to use the *other*     od.

RE: POSIX::strftime

(OP)
I think we should all just adopt the British format.  It would save us a lot of fuss over here in the UK.  ;O)

RE: POSIX::strftime

You're probably best off keeping two variables, one for display to your users and one for inserting into the database.  If all of the database interaction code is isolated, I'd make $now be for display and create a new variable for use with the database -- whichever way would involve the fewest changes.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close