Hello,
maybe if the start date and end date are near you can grep for each date in the interval and for each date format.
If the difference between dates is a year...this "solution" is not very nice.
Sorry, I read again your message and is it possible you want to create different date formats from one enter by a user?
So, you can do this:
FECHA=date entered by the user y dd.mm.yyyy format
$day=$(echo $FECHA | cut -d . -f 1)
$mont=$(echo $FECHA | cut -d . -f 2)
$year=$(echo $FECHA | cut -d . -f 3)
And now, you only have to echo in the desired order..
---------- Post updated at 06:09 PM ---------- Previous update was at 05:38 PM ----------
Last edited by albertogarcia; 05-07-2010 at 12:52 PM..
Hi all!
I'm working on a HPUX system, and I was wondering if there is a simple way to convert a date from seconds (since 1970) to a normal date.
Thanks (2 Replies)
when I ssh and run date command, it shows date in 24 hour date format.
But when I telnet the same server, it shows date in 12 hour format, ie. in AM/PM (1 Reply)
Hi,
Following are the results of various date formats:
1. date +%h" "%d
Result: Jun 02
2. date
Result: Tue Jun 2 09:59:15 CDT 2009
If i use the date format as date +%h%d then i am getting the date as 02. I want the day to be displayed as "2" instead of "02".
so my result should... (1 Reply)
Hi,
I need convert a date string to date.
For eaxmple
$last_date=6/2/2009
and I want to change the format of the above mentioned date to "Jun 2 2009 12:00AM".
Do we have any functionality or staright method to convert to the desired format? (4 Replies)
Hello,
I have a log file for the year, which contains lines starting with the data in the format of YYYY-MM-DD. I need to get all the lines that contain the DD being 04, how would I do this? I tried using grep "*-*04" but it didn't work.
Any quick one liners I should know about?
Thank you. (2 Replies)
Dear all,
I have 2 questions.
I have a file with many rows which has date of the format YYYYMMDD.
1. I need to change the date to that weeks friday date(Ex: 20120716(monday) to 20120720). Satuday/Sunday has to be changed to next week friday date too.
2. After converting the date to... (10 Replies)
I'd like to convert a date string in the form of sun aug 19 09:03:10 EDT 2012, to unixtime timestamp using awk.
I tried
This is how each line of the file looks like, different date and time in this format
Sun Aug 19 08:33:45 EDT 2012, user1(108.6.217.236) all: test on the 17th
... (2 Replies)
hello,
i have a lot of C old code I'm updating to C11 with tgmath.h for generic math. the old code has very specific types, real and complex, like cabsl, csinhl, etc
usually for simple bulk replacements i would do something simple like this
perl -pi -e 's/cosl/cos/g' *.c
the reference... (0 Replies)
Hi,
I have a string date to my unix script(sun solaris). I wanted to convert it into unix date so that I can use it in a conditional statement. Please see below:
MyTest.sh -s 2018-05-09
suppdt=$1 # string date passed via arguement as 2018-04-09
curryr=`date '+%Y'`
nextyr=`expr... (2 Replies)
Discussion started by: Saanvi1
2 Replies
LEARN ABOUT PHP
datetime.__construct
DATETIME.__CONSTRUCT(3) 1 DATETIME.__CONSTRUCT(3)DateTime::__construct - Returns new DateTime object
Object oriented style
SYNOPSIS
public DateTime::__construct NULL ([string $time = "now"], [DateTimeZone $timezone])
DESCRIPTION
Procedural style
DateTime date_create NULL ([string $time = "now"], [DateTimeZone $timezone])
Returns new DateTime object.
PARAMETERS
o $time
-A date/time string. Valid formats are explained in Date and Time Formats. Enter NULL here to obtain the current time when using
the $timezone parameter.
o $timezone
- A DateTimeZone object representing the timezone of $time. If $timezone is omitted, the current timezone will be used.
Note
The $timezone parameter and the current timezone are ignored when the $time parameter either is 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. Procedural style returns FALSE on failure.
ERRORS /EXCEPTIONS
Emits Exception in case of an error.
CHANGELOG
+--------+---------------------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+---------------------------------------------------+
| 5.3.0 | |
| | |
| | If $time contains an invalid date/time format, |
| | then an exception is now thrown. Previously an |
| | error was emitted. |
| | |
+--------+---------------------------------------------------+
EXAMPLES
Example #1
DateTime.__construct(3) example
Object oriented style
<?php
try {
$date = new DateTime('2000-01-01');
} catch (Exception $e) {
echo $e->getMessage();
exit(1);
}
echo $date->format('Y-m-d');
?>
Procedural style
<?php
$date = date_create('2000-01-01');
if (!$date) {
$e = date_get_last_errors();
foreach ($e['errors'] as $error) {
echo "$error
";
}
exit(1);
}
echo date_format($date, 'Y-m-d');
?>
The above examples will output:
2000-01-01
Example #2
Intricacies of DateTime.__construct(3)
<?php
// Specified date/time in your computer's time zone.
$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:sP') . "
";
// Specified date/time in the specified time zone.
$date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru'));
echo $date->format('Y-m-d H:i:sP') . "
";
// Current date/time in your computer's time zone.
$date = new DateTime();
echo $date->format('Y-m-d H:i:sP') . "
";
// Current date/time in the specified time zone.
$date = new DateTime(null, new DateTimeZone('Pacific/Nauru'));
echo $date->format('Y-m-d H:i:sP') . "
";
// Using a UNIX timestamp. Notice the result is in the UTC time zone.
$date = new DateTime('@946684800');
echo $date->format('Y-m-d H:i:sP') . "
";
// Non-existent values roll over.
$date = new DateTime('2000-02-30');
echo $date->format('Y-m-d H:i:sP') . "
";
?>
The above example will output something similar to:
2000-01-01 00:00:00-05:00
2000-01-01 00:00:00+12:00
2010-04-24 10:24:16-04:00
2010-04-25 02:24:16+12:00
2000-01-01 00:00:00+00:00
2000-03-01 00:00:00-05:00
SEE ALSO DateTime.createFromFormat(3), DateTimeZone.__construct(3), Date and Time Formats, date.timezone ini setting, date_default_time-
zone_set(3), DateTime.getLastErrors(3), checkdate(3).
PHP Documentation Group DATETIME.__CONSTRUCT(3)