473,396 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Convert 20080928014155 to date time in perl?

I have 2 questions:
1.When I read the number using (\S+) its getting stored as 2.08E13.
Code I used:
Expand|Select|Wrap|Line Numbers
  1. if ($line=~/4_begindt_(\S+)/) {
  2. print "$1\n"    }
  3. # $1=2.08E13; instead $1 should contain 20080928014155
  4.  
How to read and store a 15digit number in perl?

2.Once I store the number how do I convert to date and time?
like 09/28/2008 01:41:55

Please let me know
Oct 1 '08 #1
7 1841
Icecrack
174 Expert 100+
First off Use Code Tags,

Second don't store var's as $0 - $9 this is perl Special Var's

3rd, Try:

Expand|Select|Wrap|Line Numbers
  1. $a=20080928014155;
now try this your self we are not a scripting/programing service when you do, paste code with errors or problems.
Oct 1 '08 #2
KevinADC
4,059 Expert 2GB
When I do this:

Expand|Select|Wrap|Line Numbers
  1. $line = '4_begindt_20080928014155';
  2. if ($line=~/4_begindt_(\S+)/) {
  3.    print "$1\n";
  4. }
the output is: 20080928014155
Oct 1 '08 #3
KevinADC
4,059 Expert 2GB
First off Use Code Tags,

Second don't store var's as $0 - $9 this is perl Special Var's

3rd, Try:

Expand|Select|Wrap|Line Numbers
  1. $a=20080928014155;
now try this your self we are not a scripting/programing service when you do, paste code with errors or problems.
I think you misunderstood. He is not using $1 as a private variable but as the capturing group from the regexp, he just added the "=" symbol to show what its value is and what he wants it to be.
Oct 1 '08 #4
Icecrack
174 Expert 100+
When I do this:

Expand|Select|Wrap|Line Numbers
  1. $line = '4_begindt_20080928014155';
  2. if ($line=~/4_begindt_(\S+)/) {
  3.    print "$1\n";
  4. }
the output is: 20080928014155

that would be correct because of the reg exp the $1 prints first of the last reg exp matched.

what OS are you using as well?


Note: yeah just seen that. because of the non code tags i missed the #
Oct 1 '08 #5
I am using Windows.
Thats true I am capturing the whole number into $1 using regex.
Should code tags be used for capturing large numbers using regex, ?
Oct 1 '08 #6
numberwhun
3,509 Expert Mod 2GB
To convert the string of numbers into the format you want, you will probably have to look at one of the data modules on CPAN, such as this one. But there are a bunch of others depending on what you want to do.

Regards,

Jeff
Oct 1 '08 #7
KevinADC
4,059 Expert 2GB
I am using Windows.
Thats true I am capturing the whole number into $1 using regex.
Should code tags be used for capturing large numbers using regex, ?
The "code" tags is for posting code on this forum, nothing to do with perl. I am also using my old W98 server with activeperl 5.8.8 installed and I do not get the output you are getting. Is there more to your code?
Oct 1 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Manzoorul Hassan | last post by:
I need to convert a date / time to NTP Timestamp, in HEX no less, and was wondering if there might be a module for it. Any ideas? I have been searching for NTP Timestamp under Perl but have not...
10
by: Newsscanner | last post by:
Hello, In my MySQL database, one of the fields eople have to fill in is "DOB" (Date of Birth). I have now managed to begin inserting data into my DB via a form, the data type for the DOB field...
2
by: yxq | last post by:
Hello, I found there are some date formats in the email header, for example: Fri, 23 Sep 2005 08:51:56 +0800 Sat, 17 Sep 2005 09:08:07 Wed Oct 19 13:40:23 2005 19 Oct 2005 13:40:23 +0000...
5
by: Ray | last post by:
I have a table with some audit date and time columns. Problem is the developer who stored the data left them as DECIMAL type instead of DATE and TIME. Is there a way I can convert the DECIMAL type...
5
by: Extremest | last post by:
I have a bunch of dates in a couple different formats. I would like to convert them to epoch. The dates are like this Mon, 12 Jun 2006 09:18:22 GMT 12 Jun 2006 10:37:28 GMT I can do this in...
8
by: deepak_kamath_n | last post by:
Hello, I have the following scenario: 1. My application receives the date from another application as a string 2. The other application is running in a different time zone as compared to my...
12
by: jonathan184 | last post by:
Hi the purpose of the script I am trying to do is to access a dir and run the ls -l command which will show the files and the modified date, no w the script is to check two files in that dir , if the...
3
by: Rocko | last post by:
Hi, Wishing you a very Happy New Year!! I am new to perl and I need to know that how to get the current date & time in my perl script. I am working on Windows XP. my code snippet is like this: ...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.