I have a question about timestamps hope you can help me.
I'm reading one timestamp column from excel to matlab using;
[temp, timestamps] = xlsread('2012_15min.xls', 'JAN', 'A25:A2999');
This column have date like this:
01-01-2012 00:00
01-01-2012 00:15
01-01-2012 00:30
01-01-2012 00:45
01-01-2012 01:00
(it goes on until the end of January in periods of 15 minutes)
Now I want to get a new column in matlab that keeps only year month day and hour, this data must be separated and I don't want to keep repetitive dates (e.g I don't want to get 4 dates with 01 01 2012 0 only one of that)
So I want to get:
01 01 2012 0
01 01 2012 1
01 01 2012 2
It must go until the end of January with periods of 1 hour.
If you know that there is data for every hour you could construct this directly, but if you have possible missing data and you therefore need to convert from your timestamps, then some combination of datestr/datenum/datevec is usually the best bet.
First, convert timestamps with datevec:
times = datevec(timestamps); % sometimes need to also use format string
Then, take only the year/month/day/hour, removing repetitions:
[times_hours,m,n] = unique(times(:,1:4), 'rows');
You can use the indices in m to extract the matching data for those times.
If you want this converted back to some sort of string you can use datestr and specify format:
timesout = datestr(times_hours,'dd mm yyyy hh');
Related
I'm a bit rubbish on Google Sheets formulas... would anyone be so kind to tell me how to achieve this ?
I'd like to have a cell that returns the last Friday's date on Sat to Wed, and instead the current date for Thursdays and Fridays.
Is it possible ?
e.g. this coming days:
Sat to Wed returns Friday 12th of March
Thu 18th returns Thu 18th
Fri 19th return Fri 19th
... and so on.
Thanks!
There are many ways to accomplish this, but try this:
=IF((WEEKDAY(TODAY())=5)+(WEEKDAY(TODAY())=6),TODAY(),TODAY()-VLOOKUP(WEEKDAY(TODAY()),{7,1; 1,2; 2,3; 3,4; 4,5},2,FALSE))
This formula is based on the us default numbers for weekdays, where Sunday = 1. If this formula produces unexpected results, your locale may be one where Monday = 1. In this case, you'll need to adjust as follows:
=IF((WEEKDAY(TODAY())=4)+(WEEKDAY(TODAY())=5),TODAY(),TODAY()-VLOOKUP(WEEKDAY(TODAY()),{6,1; 7,2; 1,3; 2,4; 3,5},2,FALSE))
Other things to keep in mind:
The + in (WEEKDAY(TODAY())=5)+(WEEKDAY(TODAY())=6) means OR (where * would mean AND).
The VLOOKUP is looking up the weekday of TODAY() within a simple virtual array, which is formed between the curly brackets and which instructs how many days to subtract from TODAY() given the current weekday in order to arrive at the previous Friday.
I have a tableau worksheet that shows a count of records by date. Current system date is Mar 14 but my dataset has data only till Mar 9. Is it possible to show dates from Mar 10 - Mar 14 even though there is no data for this time frame.
Given is a snapshot of my worksheet, kindly let me know how could I include all dates in the row even though there is no data for this time period.
Select discrete row it will show the date on a sheet
I am getting an exif date value like
EXIFPhotoDate: 1506173228000 and
UploadDate: 1506485214000
but I know it is
EXIFPhotoDate 23/9/2017, 23:27 and
UploadDate 9/27/2017, 01:59
The former is when queried via REST and the latter is when queried via the table.
How can I get standard date/time from a value like this?
Looks like you have a number of milliseconds since January 01 1970 in UTC. If you remove the 000 from the end, you will have a Unix timestamp, that is, the number of seconds since January 01 1970 in UTC:
unixTimestamp = 1506173228000 / 1000
Once your question doesn't state any programming language, it's hard to give you further help.
I need to assign a variable with the value in the format YYYYMM e.g for today run the previous month values should be generated as
Var1 = 201607
Is there any in build method available? Could you share the steps to generate this?
The trick in these cases is to subtract one month from the day 15 of the current month:
$ date --date="$(date +%Y-%m-15) - 1 month"
Fri Jul 15 00:00:00 CEST 2016
Then it is just a matter of using the proper format:
$ date --date="$(date +%Y-%m-15) - 1 month" "+%Y%m"
201607
To store the value in a var, just use the common var=$(command) syntax.
From GNU Coreutils → 28.7 Relative items in date strings:
The fuzz in units can cause problems with relative items. For example,
‘2003-07-31 -1 month’ might evaluate to 2003-07-01, because 2003-06-31
is an invalid date. To determine the previous month more reliably, you
can ask for the month before the 15th of the current month. For
example:
$ date -R
Thu, 31 Jul 2003 13:02:39 -0700
$ date --date='-1 month' +'Last month was %B?'
Last month was July?
$ date --date="$(date +%Y-%m-15) -1 month" +'Last month was %B!'
Last month was June!
Also, take care when manipulating dates around clock changes such as
daylight saving leaps. In a few cases these have added or subtracted
as much as 24 hours from the clock, so it is often wise to adopt
universal time by setting the TZ environment variable to ‘UTC0’ before
embarking on calendrical calculations.
I would like a spreadsheet row to contain the date of today, but only on every other Thursday, changing at 9:30 am.
To give you an example:
Next thursday the 21.07.16 it shell contain "21.07.16".
Until in exactly 14 days on thursday the 4.08.16 it shell contain this date and than change to 4.08.16.
Also I would like this change to happen at 9:30 am.
I can not think of a way how to do this. Can you point me into a direction?
One has to set a starting datetime somewhere in the past, such as July 7, 2016, at 9:30am.
Then find the difference between the current and the starting datetime. Truncate this difference down to a multiple of 14, and add this value to the starting datetime.
The datetimes are represented in Sheets numerically as the number of days since December 30, 1899. In this system, 2016-07-07 9:30 is about 42558.4 So the formula would be
=42558.4 + 14*floor((now()-42558.4)/14)
The output should be formatted as a date.
A less cryptic version is
=value("2016-07-07 09:30") + 14*floor((now() - value("2016-07-07 09:30"))/14)
(value follows the local convention for parsing dates, but I hope the format I used will be understood universally.)