- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- manipulate string with perl
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2006 12:00 AM
тАО09-08-2006 12:00 AM
I have a date
my $date = 200609061700;
That I need to look like
2006-09-06 17:00
At the moment I have got as far as
my @date=split(//, $date);
my $newdate = "@date[0,1,2,3]-@date[4,5]-@date[6,7] @date[8,9]:@date[10,11]";
$newdate =~ s/\s//g;
Which gives
2006-09-0617:00
Any help appreciated
TIA
Steve
Solved! Go to Solution.
- Tags:
- date arithmetic
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2006 12:09 AM
тАО09-08-2006 12:09 AM
Re: manipulate string with perl
You can also look at modules Date::Calc, and Date::Manip
http://search.cpan.org/search?query=Date%3A%3A&mode=all
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2006 12:11 AM
тАО09-08-2006 12:11 AM
Re: manipulate string with perl
my $newdate = "$y-$m-$d $H:$M";
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2006 12:11 AM
тАО09-08-2006 12:11 AM
Re: manipulate string with perl
Sorry, I have obtained the date from a file name. I need to insert that date into my database in the format that it expects for the column
Thanks
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2006 12:13 AM
тАО09-08-2006 12:13 AM
Re: manipulate string with perl
#!/usr/bin/perl
$date=200609061700;
$year=substr $date, 0, 4;
$mnth=substr $date, 4, 2;
$day=substr $date, 6, 2;
$time=substr $date, 8, 5;
my $newdate = "$year-$mnth-$day $time\n";
print $newdate;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2006 12:14 AM
тАО09-08-2006 12:14 AM
Re: manipulate string with perl
I was also looking a substr but could only work out from the examples how to insert one character.
TIA
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2006 12:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2006 12:20 AM
тАО09-08-2006 12:20 AM
Re: manipulate string with perl
of course the unpack is a better solution than mine. I'm going to have dig into unpack more one of these days.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2006 12:24 AM
тАО09-08-2006 12:24 AM
Re: manipulate string with perl
Steve