Smart questions
Smart answers
Smart people
Join Tek-Tips Forums

Member Login

Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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.

andy98 (Programmer) (OP)
3 Feb 04 4:01

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?
ishnid (Programmer)
3 Feb 04 6:25
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
PaulTEG (TechnicalUser)
3 Feb 04 8:16
Try this instead of using POSIX functions

$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";

andy98 (Programmer) (OP)
3 Feb 04 11:11
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/ 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/ line 78.

ishnid (Programmer)
3 Feb 04 11:16
Looks like you've an SQL error at line 78.
andy98 (Programmer) (OP)
3 Feb 04 11:20
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);
Helpful Member!  rosenk (Programmer)
3 Feb 04 14:15
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.
andy98 (Programmer) (OP)
4 Feb 04 2:57
So how do I configure SQL Server to understand my date format?
andy98 (Programmer) (OP)
4 Feb 04 6:23
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.
ishnid (Programmer)
4 Feb 04 8:57
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.
andy98 (Programmer) (OP)
4 Feb 04 9:02
I think we should all just adopt the British format.  It would save us a lot of fuss over here in the UK.  ;O)
rosenk (Programmer)
4 Feb 04 10:47
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!

Back To Forum

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