Sponsored Content
Full Discussion: Check data and time
Top Forums Shell Programming and Scripting Check data and time Post 302361557 by thegeek on Tuesday 13th of October 2009 01:43:48 PM
Old 10-13-2009
1. Numeric comparison what you are doing is wrong.. You can use, -eq, -ge, -le.

For this requirement, the following works,
Code:
#!/bin/sh
day=`date`
time=`echo $day | cut -d" " -f4`
hour=`echo $time | cut -d":" -f1`
minute=`echo $time | cut -d":" -f2`
dayname=`echo $day | cut -d" " -f1`

        if [ $dayname = 'Sat' -a $hour -ge 5 -a $minute -gt 15 ]
        then
                if [ $dayname = 'Sat' -a $hour -le 6 -a $minute -lt 50 ]
                then
            echo "its that time..";
               # Between Sat 5:15 and 6:30, do not continue.
                exit
                fi
        fi
echo "Not between Sat 5:15 and 6:50.... Continue script..."

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get data between the start time and end time?

Hi, Can anyone help me how can I get the line that between the start time and end time. file1.txt 15/03/2009 20:45:03 Request: - Data of this line 15/03/2009 20:45:12 Response: - Data of this line 15/03/2009 22:10:40 Request: - Data of this line 15/03/2009 22:10:42 Response: - Data of... (1 Reply)
Discussion started by: tanit
1 Replies

2. Shell Programming and Scripting

Check Time/Date on a server

I have two servers which are not in sync. I need to write a script that checks the time on the corresponding server and another script to call the above script on both the servers simulataneously to check if there is a time difference. Can anyone provide me with such scripts as I am new to... (3 Replies)
Discussion started by: ravneet123
3 Replies

3. UNIX for Dummies Questions & Answers

Check time and Increase counter

Hi all... the last two weeks have been very educational... I went through a bunch of websites about linux and its commands.. still not have mastered it nor its many operators ... and symbols. I wish I had more time to dig to the next and unix.com but I m on a deadline for this project. I... (2 Replies)
Discussion started by: abilash.amara
2 Replies

4. UNIX for Dummies Questions & Answers

Time check!

How can i do something, that will be doing periodicaly for 24 hours and then do something else. For example: i want to write "time" in a text file every 10 sec but only for the next 24 h and then rewrite all that data to an other file, then again write "time" in the first file every 10 sec,... (5 Replies)
Discussion started by: petel1
5 Replies

5. Shell Programming and Scripting

Check file time stamp

Hi, I need help to read file in a directory on basis of time stamp. e.g. If file access in last 2 minutes it should not be copy to remote directory. Below is my script. #!/bin/ksh DATE=`date +"%Y-%m-%d_%H%M"` SEPARATER=" " exec < out_interfaces.cfg while read source_path... (10 Replies)
Discussion started by: qamar.alam
10 Replies

6. Shell Programming and Scripting

how to check whether a process started at particular time

I want to check whether a particular process has started at 10:00a.m or not. I can check process by ps -fu but dont know how to check it with respect to time. Could anyone help me with this? ---------- Post updated at 11:14 AM ---------- Previous update was at 10:52 AM ---------- can i use... (9 Replies)
Discussion started by: kishore kumar
9 Replies

7. Shell Programming and Scripting

IF loop to check the time modified

Hi Frnds, i have a folder test in which files generated daily how to chek the files that are modified on that day as a condition for ex, if then echo "i have got something to do with the file" else echo" sorry" fi i will have more than 3 to 4 files that are modified today. and if... (5 Replies)
Discussion started by: mahesh300182
5 Replies

8. Programming

Find gaps in time data and replace missing time value and column 2 value by interpolation in awk

Dear all, I am kindly seeking assistance on the following issue. I am working with data that is sampled every 0.05 hours (that is 3 minutes intervals) here is a sample data from the file 5.00000 15.5030 5.05000 15.6680 5.10000 16.0100 5.15000 16.3450 5.20000 16.7120 5.25000... (4 Replies)
Discussion started by: malandisa
4 Replies

9. Shell Programming and Scripting

Check if time format is valid

How can I validate if time (HH:MM:SS) argument is valid? I got this from web but I can't modify it to exit the script if the time argument is invalid. echo $1 | awk -F ':' '{ print ($1 <= 23 && $2 <= 59 && $3 <= 59) ? "good" : "bad" }' ex: ./script.ksh 12:34:21 = okay ./script.ksh... (10 Replies)
Discussion started by: erin00
10 Replies
DATETIME.CREATEFROMFORMAT(3)						 1					      DATETIME.CREATEFROMFORMAT(3)

DateTime::createFromFormat - Returns new DateTime object formatted according to the specified format

       Object oriented style

SYNOPSIS
publicstatic DateTime DateTime::createFromFormat (string $format, string $time, [DateTimeZone $timezone]) DESCRIPTION
Procedural style DateTime date_create_from_format (string $format, string $time, [DateTimeZone $timezone]) Returns new DateTime object formatted according to the specified format. PARAMETERS
o $format - The format that the passed in string should be in. See the formatting options below. In most cases, the same letters as for the date(3) can be used. The following characters are recognized in the $format parameter string +--------------------------+--------------------------------------+---+ | $format character | | | | | | | | | Description | | | | | | | | Example parsable values | | | | | | +--------------------------+--------------------------------------+---+ | | | | | Day | | | | | | | | | --- | | | | | | | | --- | | | | | | | | | | | d and j | | | | | | | | | Day of the month, 2 digits with or | | | | without leading zeros | | | | | | | | | | | | 01 to 31 or 1 to 31 | | | | | | | | | | | D and l | | | | | | | | | A textual representation of a day | | | | | | | | | | | | Mon through Sun or Sunday through | | | | Saturday | | | | | | | | | | | S | | | | | | | | | English ordinal suffix for the day | | | | of the month, 2 characters. It's | | | | ignored while processing. | | | | | | | | | | | | st, nd, rd or th. | | | | | | | | | | | z | | | | | | | | | The day of the year (starting from | | | | 0) | | | | | | | | | | | | 0 through 365 | | | | | | | | | | | Month | | | | | | | | | --- | | | | | | | | --- | | | | | | | | | | | F and M | | | | | | | | | A textual representation of a month, | | | | such as January or Sept | | | | | | | | | | | | January through December or Jan | | | | through Dec | | | | | | | | | | | m and n | | | | | | | | | Numeric representation of a month, | | | | with or without leading zeros | | | | | | | | | | | | 01 through 12 or 1 through 12 | | | | | | | | | | | Year | | | | | | | | | --- | | | | | | | | --- | | | | | | | | | | | Y | | | | | | | | | A full numeric representation of a | | | | year, 4 digits | | | | | | | | Examples: 1999 or 2003 | | | | | | | | | | | y | | | | | | | | | A two digit representation of a | | | | year (which is assumed to be in the | | | | range 1970-2069, inclusive) | | | | | | | | Examples: 99 or 03 (which will be | | | | interpreted as 1999 and 2003, | | | | respectively) | | | | | | | | | | | Time | | | | | | | | | --- | | | | | | | | --- | | | | | | | | | | | a and A | | | | | | | | | Ante meridiem and Post meridiem | | | | | | | | | | | | am or pm | | | | | | | | | | | g and h | | | | | | | | | 12-hour format of an hour with or | | | | without leading zero | | | | | | | | | | | | 1 through 12 or 01 through 12 | | | | | | | | | | | G and H | | | | | | | | | 24-hour format of an hour with or | | | | without leading zeros | | | | | | | | | | | | 0 through 23 or 00 through 23 | | | | | | | | | | | i | | | | | | | | | Minutes with leading zeros | | | | | | | | | | | | 00 to 59 | | | | | | | | | | | s | | | | | | | | | Seconds, with leading zeros | | | | | | | | | | | | 00 through 59 | | | | | | | | | | | u | | | | | | | | | Microseconds (up to six digits) | | | | | | | | Example: 45, 654321 | | | | | | | | | | | Timezone | | | | | | | | | --- | | | | | | | | --- | | | | | | | | | | | e, O, P and T | | | | | | | | | Timezone identifier, or difference | | | | to UTC in hours, or difference to | | | | UTC with colon between hours and | | | | minutes, or timezone abbreviation | | | | | | | | Examples: UTC, GMT, Atlantic/Azores | | | | or +0200 or +02:00 or EST, MDT | | | | | | | | | | | Full Date/Time | | | | | | | | | --- | | | | | | | | --- | | | | | | | | | | | U | | | | | | | | | Seconds since the Unix Epoch (Janu- | | | | ary 1 1970 00:00:00 GMT) | | | | | | | | Example: 1292177455 | | | | | | | | | | |Whitespace and Separators | | | | | | | | | --- | | | | | | | | --- | | | | | | | | | | | (space) | | | | | | | | | One space or one tab | | | | | | | | Example: | | | | | | | | | | | # | | | | | | | | | One of the following separation | | | | symbol: ;, :, /, ., ,, -, ( or ) | | | | | | | | Example: / | | | | | | | | | | |;, :, /, ., ,, -, ( or ) | | | | | | | | | The specified character. | | | | | | | | Example: - | | | | | | | | | | | ? | | | | | | | | | A random byte | | | | | | | | Example: ^ (Be aware that for UTF-8 | | | | characters you might need more than | | | | one ?. In this case, using * is | | | | probably what you want instead) | | | | | | | | | | | * | | | | | | | | | Random bytes until the next separa- | | | | tor or digit | | | | | | | | Example: * in Y-*-d with the string | | | | 2009-aWord-08 will match aWord | | | | | | | | | | | ! | | | | | | | | | Resets all fields (year, month, day, | | | | hour, minute, second, fraction and | | | | timzone information) to the Unix | | | | Epoch | | | | | | | | Without !, all fields will be set to | | | | the current date and time. | | | | | | | | | | | | | | | | | | | | | Resets all fields (year, month, day, | | | | hour, minute, second, fraction and | | | | timzone information) to the Unix | | | | Epoch if they have not been parsed | | | | yet | | | | | | | | | | | | Y-m-d| will set the year, month and | | | | day to the information found in the | | | | string to parse, and sets the hour, | | | | minute and second to 0. | | | | | | | | | | | + | | | | | | | | | If this format specifier is present, | | | | trailing data in the string will not | | | | cause an error, but a warning | | | | instead | | | | | | | | Use DateTime::getLastErrors to find | | | | out whether trailing data was | | | | present. | | | | | | +--------------------------+--------------------------------------+---+ Unrecognized characters in the format string will cause the parsing to fail and an error message is appended to the returned struc- ture. You can query error messages with DateTime::getLastErrors. If $format does not contain the character ! then portions of the generated time which are not specified in $format will be set to the current system time. If $format contains the character !, then portions of the generated time not provided in $format, as well as values to the left-hand side of the !, will be set to correspond- ing values from the Unix epoch. The Unix epoch is 1970-01-01 00:00:00 UTC. o $time - String representing the time. o $timezone - A DateTimeZone object representing the desired time zone. If $timezone is omitted and $time contains no timezone, the current timezone will be used. Note The $timezone parameter and the current timezone are ignored when the $time parameter either contains a UNIX timestamp (e.g. 946684800) or specifies a timezone (e.g. 2010-01-28T15:00:00+02:00). RETURN VALUES
Returns a new DateTime instance or FALSE on failure. EXAMPLES
Example #1 DateTime.createFromFormat(3) example Object oriented style <?php $date = DateTime::createFromFormat('j-M-Y', '15-Feb-2009'); echo $date->format('Y-m-d'); ?> Procedural style <?php $date = date_create_from_format('j-M-Y', '15-Feb-2009'); echo date_format($date, 'Y-m-d'); ?> The above examples will output: 2009-02-15 Example #2 Intricacies of DateTime.createFromFormat(3) <?php echo 'Current time: ' . date('Y-m-d H:i:s') . " "; $format = 'Y-m-d'; $date = DateTime::createFromFormat($format, '2009-02-15'); echo "Format: $format; " . $date->format('Y-m-d H:i:s') . " "; $format = 'Y-m-d H:i:s'; $date = DateTime::createFromFormat($format, '2009-02-15 15:16:17'); echo "Format: $format; " . $date->format('Y-m-d H:i:s') . " "; $format = 'Y-m-!d H:i:s'; $date = DateTime::createFromFormat($format, '2009-02-15 15:16:17'); echo "Format: $format; " . $date->format('Y-m-d H:i:s') . " "; $format = '!d'; $date = DateTime::createFromFormat($format, '15'); echo "Format: $format; " . $date->format('Y-m-d H:i:s') . " "; ?> The above example will output something similar to: Current time: 2010-04-23 10:29:35 Format: Y-m-d; 2009-02-15 10:29:35 Format: Y-m-d H:i:s; 2009-02-15 15:16:17 Format: Y-m-!d H:i:s; 1970-01-15 15:16:17 Format: !d; 1970-01-15 00:00:00 SEE ALSO
DateTime.__construct(3), DateTime.getLastErrors(3), checkdate(3), strptime(3). PHP Documentation Group DATETIME.CREATEFROMFORMAT(3)
All times are GMT -4. The time now is 09:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy