home

Quickies, by Andrea Olivato

text

Use Zenity calendar to get dates in different formats in bash.

Quick example on how to open a calendar with Zenity, get the selected date from a Bash script, and change the returned date format (timestamp f.e.).

#!/bin/bash

# Creates a Zenity calendar obj, 
# Put the selected date on a variable.

DATE=`$(zenity --calendar --text "When to leave?" --title "Holidays"); echo $szDate`;

# If you want to return the date in a different format you can play with
# the --date-format parameter.
# The syntax is the same of date command.

# This shows how to get the timestamp
TIMESTAMP=`$(zenity --calendar --text "When to leave?" --title "Holidays" --date-format=%s); echo $szDate`

# If you want to show as first view an other month/year you can specify it with
# --day, --month and --year parameters.

# This shows how to set the date to july 2007
TIMESTAMP=`$(zenity --calendar --text "When to leave?" --title "Holidays" --day 10 --month 7 --year 2010); echo $szDate`

# Obviously you can always do whatever you want with returned values.
echo ${DATE}" - "${TIMESTAMP};

2 years ago

July 7, 2009
Comments (View)