Timstamp fun

Any trouble you encounter with the Pedias, here's the place to ask for help.
Post Reply
DriverJC
Bruji Friend
Bruji Friend
Posts: 16
Joined: Mon Aug 02, 2010 9:00 pm

Timstamp fun

Post by DriverJC »

I am working on a way to tag the movies that I convert and put into iTunes.

Presently I have to manually export the database to a txt file and query that in bash. this works great and gives me the format of the dates that I want (i.e YYYY-MM-DD).

I am able to have sqlite dump the database to a text file automatically however the timestamp for an entry is "185457600" instead of the 2006-11-17.

Is there any way I can have the dates converted to YYYY-MM-DD format either as the dump occurs or with bash when it looks up the information in the text file?

Any help would be appreciated.

Thanks for a great program.
User avatar
Conor
Top Dog
Posts: 5345
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: Timstamp fun

Post by Conor »

Sqlite3 does not allow a conversion of the timestamp to a date during the dump, but you can do it in the bash shell with the following function:

Code: Select all

stamp2date (){
	#Add seconds to match Unix reference date from Mac OS X 2001-01-01 reference date.
	seconds=$(( $1 + 978328800 ))
    date -r $seconds "+%Y-%m-%d"
}

# from timestamp to date
    stamp2date 185457600 #tested outputs "2006-11-17"
I started from this post and amended to work with Mac OS X.
Post Reply