Sponsored Content
Top Forums Shell Programming and Scripting Detect DST from a date entered by user in bash Post 302962741 by Don Cragun on Thursday 17th of December 2015 10:09:49 PM
Old 12-17-2015
I don't have access to a Linux system (so the following is untested), but the following should give you the Timezone string that applies to midnight at the start of the given date:
Code:
test_date="12/25/2000" # Format is "MM/DD/YYYY"
date -d"$test_date" +%Z

Note that on dates when there is a switch to or from daylight savings time, the answer for those two days each year (in areas where daylight savings time is observed) is not a constant for the entire day. That is why it is important to specify a specific time for the test rather than assume that the answer applies to the entire day.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

validating user entered date

I need the date validation. I searched in the google but i didn't find my requirements. requirements: 1) user has to enter the date in YYYY/MM/DD format 2) MM validations 3) DD validations. and if the month is april it should allow 30 days only and for May month it should allow 31 days like... (1 Reply)
Discussion started by: KiranKumarKarre
1 Replies

2. Shell Programming and Scripting

Determine if given date is in DST

Is there a way to figure out if given date is in DST or in EST? So imagine a shell script is_date_dst.sh sh is_date_dst.sh 2009-03-02 would return 0 and sh is_date_dst.sh 2009-03-22 would return 1 This script should not assume the timezone of the machine it runs on, but only the date passed... (7 Replies)
Discussion started by: asriva
7 Replies

3. Shell Programming and Scripting

Detect ints and change to a Date format

Hello, I have been trying to figure out how to solve this problem and I have run into a dead end. I am trying to parse a text file that gives me a date and I need to read it into SQL server 2005 but SQL can't figure out its a time unless I put it in a different format. This is how my text file... (3 Replies)
Discussion started by: AlexDr
3 Replies

4. Shell Programming and Scripting

find files for next day of the date entered

i have few files generated everyday with a date stamp. Sometimes it happens that if the files are generated late i.e after 00:00 hrs the date stamp will be of the next day. example: 110123_file1 110123_file2 110123_file3 110124_file4 in the above example file4 is also for the previous... (2 Replies)
Discussion started by: gpk_newbie
2 Replies

5. Shell Programming and Scripting

Bash script to detect nonpingable hosts

I have a script to detect if a host is pingable or not. The problem is that I would like it to put the nonpingable hosts in one file and the pingable hosts in another. I have come up with this so far: for ip in `cat /tmp/testlist2`; do ping -c 3 $ip >/dev/null && echo "$ip is up" || echo "$ip... (5 Replies)
Discussion started by: newbie2010
5 Replies

6. Shell Programming and Scripting

Perl : accept multiple user entered command line arguemnts

I am trying to create a script that will accept multi input from the user (really just me), then execute those command on a remote device. My question is if the I enter "No" at the confirmation point "Are these statements correct y or n ?", what is the best way to go back and start over ? I... (3 Replies)
Discussion started by: popeye
3 Replies

7. Shell Programming and Scripting

To get the files in a directory for the given date (User entered date)

Need a ksh script to get the files that were created or modified in a directory on a particular date entered by the user. For example if a directory contains files as below : > ll total 41 -rw-rw-r-- 1 psn psn 199 Aug 23 07:06 psn_roll.sh -rw-rw-r-- 1 psn psn ... (10 Replies)
Discussion started by: ramprabhum
10 Replies

8. AIX

Need to get the next day's date of the user entered date

I need to get the next day's date of the user entered date for example: Enter date (yyyy/mm/yy): 2013/10/08I need to get the next day's date of the user entered date Desired Output: 2013/10/09Though there are ways to achieve this is Linux or Unix environment (date command) ,I need to... (1 Reply)
Discussion started by: rpm120
1 Replies

9. Shell Programming and Scripting

How to check user entered correct file format or not?

Hi Experts, path=/db/files/ format=$1 User can enter any file format.compare the user file format with actual file format existed in the directory /db/files. User enter all characters as "A" apart from date format. example1: user will be entering the file format AAA_AA_YYYYMMDD.AAA Actual... (6 Replies)
Discussion started by: nalu
6 Replies

10. UNIX for Beginners Questions & Answers

Noob question: How to check the total number of inputs entered by user?

Say I have this line: read -p "Enter 3 numbers: " num1 num2 num3; I want to write a while loop that repeatedly asks for input if the number of inputs entered is not equal to 3. I don't know the correct command to find the number of inputs entered. Help, please? (4 Replies)
Discussion started by: jejemonx
4 Replies
clock(n)						       Tcl Built-In Commands							  clock(n)

__________________________________________________________________________________________________________________________________________________

NAME
clock - Obtain and manipulate time SYNOPSIS
clock option ?arg arg ...? _________________________________________________________________ DESCRIPTION
This command performs one of several operations that may obtain or manipulate strings or values that represent some notion of time. The option argument determines what action is carried out by the command. The legal options (which may be abbreviated) are: clock clicks ?-milliseconds? | Return a high-resolution time value as a system-dependent integer value. The unit of the value is system-dependent but should be | the highest resolution clock available on the system such as a CPU cycle counter. If -milliseconds is specified, then the value is | guaranteed to be of millisecond granularity. This value should only be used for the relative measurement of elapsed time. clock format clockValue ?-format string? ?-gmt boolean? Converts an integer time value, typically returned by clock seconds, clock scan, or the atime, mtime, or ctime options of the file command, to human-readable form. If the -format argument is present the next argument is a string that describes how the date and time are to be formatted. Field descriptors consist of a % followed by a field descriptor character. All other characters are copied into the result. Valid field descriptors are: %% Insert a %. %a Abbreviated weekday name (Mon, Tue, etc.). %A Full weekday name (Monday, Tuesday, etc.). %b Abbreviated month name (Jan, Feb, etc.). %B Full month name. | %c | Locale specific date and time. The format for date and time in the default "C" locale on Unix/Mac is "%a %b %d %H:%M:%S %Y". | On Windows, this value is the locale specific long date and time, as specified in the Regional Options control panel set- | tings. | %C | First two digits of the four-digit year (19 or 20). %d Day of month (01 - 31). | %D | Date as %m/%d/%y. | %e | Day of month (1 - 31), no leading zeros. | %h | Abbreviated month name. %H Hour in 24-hour format (00 - 23). | %I | Hour in 12-hour format (01 - 12). %j Day of year (001 - 366). | %k | Hour in 24-hour format, without leading zeros (0 - 23). | %l | Hour in 12-hour format, without leading zeros (1 - 12). %m Month number (01 - 12). %M Minute (00 - 59). | %n | Insert a newline. %p AM/PM indicator. | %r | Time in a locale-specific "meridian" format. The "meridian" format in the default "C" locale is "%I:%M:%S %p". | %R | Time as %H:%M. | %s | Count of seconds since the epoch, expressed as a decimal integer. %S Seconds (00 - 59). | %t | Insert a tab. | %T | Time as %H:%M:%S. | %u | Weekday number (Monday = 1, Sunday = 7). %U Week of year (00 - 52), Sunday is the first day of the week. | %V | Week of year according to ISO-8601 rules. Week 1 of a given year is the week containing 4 January. | %w | Weekday number (Sunday = 0, Saturday = 6). %W Week of year (00 - 52), Monday is the first day of the week. | %x | Locale specific date format. The format for a date in the default "C" locale for Unix/Mac is "%m/%d/%y". On Windows, this | value is the locale specific short date format, as specified in the Regional Options control panel settings. | %X | Locale specific 24-hour time format. The format for a 24-hour time in the default "C" locale for Unix/Mac is "%H:%M:%S". On | Windows, this value is the locale specific time format, as specified in the Regional Options control panel settings. %y Year without century (00 - 99). %Y Year with century (e.g. 1990) %Z Time zone name. If the -format argument is not specified, the format string "%a %b %d %H:%M:%S %Z %Y" is used. If the -gmt argument is present the | next argument must be a boolean which if true specifies that the time will be formatted as Greenwich Mean Time. If false then the local timezone will be used as defined by the operating environment. clock scan dateString ?-base clockVal? ?-gmt boolean? Convert dateString to an integer clock value (see clock seconds). This command can parse and convert virtually any standard date and/or time string, which can include standard time zone mnemonics. If only a time is specified, the current date is assumed. If the string does not contain a time zone mnemonic, the local time zone is assumed, unless the -gmt argument is true, in which case the clock value is calculated assuming that the specified time is relative to Greenwich Mean Time. -gmt, if specified, affects only the computed time value; it does not impact the interpretation of -base. If the -base flag is specified, the next argument should contain an integer clock value. Only the date in this value is used, not the time. This is useful for determining the time on a specific day or doing other date-relative conversions. The dateString consists of zero or more specifications of the following form: time A time of day, which is of the form: hh?:mm?:ss?? ?meridian? ?zone? or hhmm ?meridian? ?zone?. If no meridian is specified, hh is interpreted on a 24-hour clock. date A specific month and day with optional year. The acceptable formats are mm/dd?/yy?, monthname dd ?, yy?, dd monthname ?yy?, day, dd monthname yy, ?CC?yymmdd, ?CC?yy-mm-dd, dd-monthname-?CC?yy. The default year is the current year. If the year is less than 100, we treat the years 00-68 as 2000-2068 and the years 69-99 as 1969-1999. Not all platforms can represent the | years 38-70, so an error may result if these years are used. ISO 8601 point-in-time An ISO 8601 point-in-time specification, such as CCyymmddThhmmss, where T is the literal T, CCyymmdd hhmmss, or CCyymmd- dThh:mm:ss. relative time A specification relative to the current time. The format is number unit acceptable units are year, fortnight, month, week, day, hour, minute (or min), and second (or sec). The unit can be specified as a singular or plural, as in 3 weeks. These modifiers may also be specified: tomorrow, yesterday, today, now, last, this, next, ago. The actual date is calculated according to the following steps. First, any absolute date and/or time is processed and converted. Using that time as the base, day-of-week specifications are added. Next, relative specifications are used. If a date or day is specified, and no absolute or relative time is given, midnight is used. Finally, a correction is applied so that the correct hour of the day is produced after allowing for daylight savings time differences and the correct date is given when going from the end of a long month to a short month. Daylight savings time correction is applied only when the relative time is specified in units of days or more, ie, days, weeks, fortnights, months or years. This means that when crossing the daylight savings time boundary, different results will be given for clock scan "1 day" and clock scan "24 hours": % clock scan "1 day" -base [clock scan 1999-10-31] 941443200 % clock scan "24 hours" -base [clock scan 1999-10-31] 941439600 clock seconds Return the current date and time as a system-dependent integer value. The unit of the value is seconds, allowing it to be used for relative time calculations. The value is usually defined as total elapsed time from an ``epoch''. You shouldn't assume the value of the epoch. SEE ALSO
date(1), time(n) KEYWORDS
clock, date, time Tcl 8.4 clock(n)
All times are GMT -4. The time now is 10:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy