Sponsored Content
Top Forums Shell Programming and Scripting convert date format to mysql date format in log file Post 302293480 by hazno on Tuesday 3rd of March 2009 07:00:16 AM
Old 03-03-2009
convert date format to mysql date format in log file

I have a comma delimited log file which has the date as MM/DD/YY in the 2nd column, and HH:MM:SS in the 3rd column.

I need to change the date format to YYYY-MM-DD and merge it with the the time HH:MM:SS. How will I got about this?

Sample input

Code:
02/27/09,23:52:31
02/27/09,23:52:52
02/27/09,23:54:53
02/27/09,23:57:46

Desired output
Code:
2009-02-27 23:52:31

thanks & regards
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

convert mmddyy date format to ccyyddd format??

hi, for reading a cobol indexed file i need to convert "mmddyy" date format to "ccyyddd" format. i checked the datecalc and other scripts but couldnt modify them to cater to my need:(... The datecalc gives an output which i believe is the total days till that date, but i want to convert it... (2 Replies)
Discussion started by: Bhups
2 Replies

2. UNIX for Dummies Questions & Answers

Convert date format

Hi All, Need your help in converting a date format in ksh. I'm currently working on SUN os where my script is getting a date from a table. The result returns to ksh in this format: 17-JUL-08 How do i convert this string to a date format like yyyymmdd? I tried #!/bin/ksh d="17-JUL-08"... (5 Replies)
Discussion started by: agathaeleanor
5 Replies

3. Shell Programming and Scripting

Convert Epoch time format to normal date time format in the same file

I have a file named "suspected" with series of line like these : {'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '219.78.120.166', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 8291, 'time': 1226506312L, 'serverhostname': ''} {'protocol': 17, 'service': 'BitTorrent... (3 Replies)
Discussion started by: rk4k
3 Replies

4. UNIX for Dummies Questions & Answers

Changing from Excel date format to MySQL date format

I have a list of dates in the following format: mm/dd/yyyy and want to change these to the MySQL standard format: yyyy-mm-dd. The dates in the original file may or may not be zero padded, so April is sometimes "04" and other times simply "4". This is what I use to change the format: sed -i '' -e... (2 Replies)
Discussion started by: figaro
2 Replies

5. Shell Programming and Scripting

convert date format

I've been using this thread: https://www.unix.com/shell-programming-scripting/58675-change-date-dd-mmm-yyyy-mm-dd-yyyy.html and https://www.unix.com/shell-programming-scripting/14655-changing-yyyy-mm-dd-ddmmyy.html and this code: on this format: 05/16/2008 18:30:49 Installation 48985and I'm... (3 Replies)
Discussion started by: dba_frog
3 Replies

6. Shell Programming and Scripting

Convert the date format from mdy to ymd in column of file

The date format in the delimited file for one column '6/27/2011 12:00:00 AM' Is it possible o change it to '2011-06-27 12:00:00 AM' for all the records.. Thanks in advance..... (8 Replies)
Discussion started by: infernalhell
8 Replies

7. Shell Programming and Scripting

Need a unix script to convert date into Julian format in a text file

The 6th & 7th column of the text files represents date & time. I need this to be converted in julian format using command "date +%s -d <date>". I know the command, but dont know how to use it on the script 0 dbclstr-b IXT_Web Memphis_Prod_SQL_Full Memphis-Prod-SQL-Full-Application-Backup... (4 Replies)
Discussion started by: ajiwww
4 Replies

8. UNIX for Dummies Questions & Answers

Rename all Files in a UNIX Directory from one date format to another date format

Hi Unix Gurus, I would like to rename several files in a Unix Directory . The filenames can have more than 1 underscore ( _ ) and the last underscore is always followed by a date in the format mmddyyyy. The Extension of the files can be .txt or .pdf or .xls etc and is case insensitive ie... (1 Reply)
Discussion started by: pchegoor
1 Replies

9. Shell Programming and Scripting

Convert Date Format

Hello, I want to change the format of date value in variable. e.g. cur_date = '2013/03/13 14:24:50' (yyyy/mm/dd hh24:mi:ss) I want to change this to '13-MAR-2013 14:24:50 Following code coverts the current date to format I am looking for. But I do not know how this can be done for a date... (8 Replies)
Discussion started by: cartrider
8 Replies

10. Shell Programming and Scripting

Convert date format

Hi guys I am looking to convert this kind of entry in a txt file 26/04/2008 to April 2008 Note : this is not using the date command , these are date entries in a file can i do this with sed ? Use code tags, thanks. (5 Replies)
Discussion started by: johnnybananas
5 Replies
DBIx::Class::InflateColumn::DateTime(3pm)		User Contributed Perl Documentation		 DBIx::Class::InflateColumn::DateTime(3pm)

NAME
DBIx::Class::InflateColumn::DateTime - Auto-create DateTime objects from date and datetime columns. SYNOPSIS
Load this component and then declare one or more columns to be of the datetime, timestamp or date datatype. package Event; use base 'DBIx::Class::Core'; __PACKAGE__->load_components(qw/InflateColumn::DateTime/); __PACKAGE__->add_columns( starts_when => { data_type => 'datetime' } create_date => { data_type => 'date' } ); Then you can treat the specified column as a DateTime object. print "This event starts the month of ". $event->starts_when->month_name(); If you want to set a specific timezone and locale for that field, use: __PACKAGE__->add_columns( starts_when => { data_type => 'datetime', timezone => "America/Chicago", locale => "de_DE" } ); If you want to inflate no matter what data_type your column is, use inflate_datetime or inflate_date: __PACKAGE__->add_columns( starts_when => { data_type => 'varchar', inflate_datetime => 1 } ); __PACKAGE__->add_columns( starts_when => { data_type => 'varchar', inflate_date => 1 } ); It's also possible to explicitly skip inflation: __PACKAGE__->add_columns( starts_when => { data_type => 'datetime', inflate_datetime => 0 } ); NOTE: Don't rely on "InflateColumn::DateTime" to parse date strings for you. The column is set directly for any non-references and "InflateColumn::DateTime" is completely bypassed. Instead, use an input parser to create a DateTime object. For instance, if your user input comes as a 'YYYY-MM-DD' string, you can use "DateTime::Format::ISO8601" thusly: use DateTime::Format::ISO8601; my $dt = DateTime::Format::ISO8601->parse_datetime('YYYY-MM-DD'); DESCRIPTION
This module figures out the type of DateTime::Format::* class to inflate/deflate with based on the type of DBIx::Class::Storage::DBI::* that you are using. If you switch from one database to a different one your code should continue to work without modification (though note that this feature is new as of 0.07, so it may not be perfect yet - bug reports to the list very much welcome). If the data_type of a field is "date", "datetime" or "timestamp" (or a derivative of these datatypes, e.g. "timestamp with timezone"), this module will automatically call the appropriate parse/format method for deflation/inflation as defined in the storage class. For instance, for a "datetime" field the methods "parse_datetime" and "format_datetime" would be called on deflation/inflation. If the storage class does not provide a specialized inflator/deflator, "[parse|format]_datetime" will be used as a fallback. See DateTime::Format for more information on date formatting. For more help with using components, see "USING" in DBIx::Class::Manual::Component. register_column Chains with the "register_column" in DBIx::Class::Row method, and sets up datetime columns appropriately. This would not normally be directly called by end users. In the case of an invalid date, DateTime will throw an exception. To bypass these exceptions and just have the inflation return undef, use the "datetime_undef_if_invalid" option in the column info: "broken_date", { data_type => "datetime", default_value => '0000-00-00', is_nullable => 1, datetime_undef_if_invalid => 1 } USAGE NOTES
If you have a datetime column with an associated "timezone", and subsequently create/update this column with a DateTime object in the DateTime::TimeZone::Floating timezone, you will get a warning (as there is a very good chance this will not have the result you expect). For example: __PACKAGE__->add_columns( starts_when => { data_type => 'datetime', timezone => "America/Chicago" } ); my $event = $schema->resultset('EventTZ')->create({ starts_at => DateTime->new(year=>2007, month=>12, day=>31, ), }); The warning can be avoided in several ways: Fix your broken code When calling "set_time_zone" on a Floating DateTime object, the timezone is simply set to the requested value, and no time conversion takes place. It is always a good idea to be supply explicit times to the database: my $event = $schema->resultset('EventTZ')->create({ starts_at => DateTime->new(year=>2007, month=>12, day=>31, time_zone => "America/Chicago" ), }); Suppress the check on per-column basis __PACKAGE__->add_columns( starts_when => { data_type => 'datetime', timezone => "America/Chicago", floating_tz_ok => 1 } ); Suppress the check globally Set the environment variable DBIC_FLOATING_TZ_OK to some true value. Putting extra attributes like timezone, locale or floating_tz_ok into extra => {} has been DEPRECATED because this gets you into trouble using DBIx::Class::Schema::Versioned. Instead put it directly into the columns definition like in the examples above. If you still use the old way you'll see a warning - please fix your code then! SEE ALSO
More information about the add_columns method, and column metadata, can be found in the documentation for DBIx::Class::ResultSource. Further discussion of problems inherent to the Floating timezone: Floating DateTimes and $dt->set_time_zone AUTHOR
Matt S. Trout <mst@shadowcatsystems.co.uk> CONTRIBUTORS
Aran Deltac <bluefeet@cpan.org> LICENSE
You may distribute this code under the same terms as Perl itself. perl v5.14.2 2011-08-19 DBIx::Class::InflateColumn::DateTime(3pm)
All times are GMT -4. The time now is 03:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy