Strip time/date/year from datetime wave

Hi,

Is there an easy way to strip the 'date' or 'time' or 'year from the date' from a date-time wave? I have a multi-year sampling data, and I want to manipulate the data based on day and month, but not year. For example: Add the data collected on date 01/01 over all the years of sampling.

Thanks

Hi,

I cobbled something together quickly so please double check.

Basically it assumes the incoming wave is just a numeric wave with the timestamp. I make a three column wave for year, month and day values.  I request the time to date conversion with the result a string and then parse out the appropriate values to the corresponding columns.

From their I would make use of the extract function to create subset of the data of interest for further analysis.

Function Time2DateColumns(wave timewave)

    variable index,maxindex
    maxindex = numpnts(timewave)
    Make/O /n=(maxindex,3) output
    Wave output
    variable year, month, day
    setdimlabel 1,0, year, output
    setdimlabel 1,1,month, output
    setdimlabel 1,2,day, output
   
    for(index=0;index<maxindex;index+=1)
        sscanf secs2date(timewave[index],-2),"%d-%d-%d", year,month,day
        output[index][%year]=year
        output[index][%month]=month
        output[index][%day] = day
       
    endfor
end

Is this of help?

 

Andy

Hi,

I would direct you to Secs2Time to start you will need to figure out how you want to handle the time.  Are you going to bin it by hour, or range of hours or just as # seconds after midnight.

Andy

Secs2Time(seconds, format [, fracDigits ])
The Secs2Time function returns a string containing a time.
Parameters
seconds  is the number of seconds from 1/1/1904 to the time to be returned.
format  is a number between 0 and 5 which specifies how the time is to be constructed. It is interpreted as follows:
0:    Normal time, no seconds.
1:    Normal time, with seconds.
2:    Military time, no seconds.
3:    Military time, with seconds and optional fractional seconds.
4:    Elapsed time, no seconds.
5:    Elapsed time, with seconds and optional fractional seconds.

"Normal" formats (0 and 1) follow the preferred formatting of the short time format as set in the International control panel (Macintosh ) or in the Regional and Language Options control panel (Windows ).
"Military" means that the hour is a number from 0 to 23. Hours greater than 23 are wrapped.
"Elapsed" means that the hour is a number from -9999 to 9999. The result for hours outside that range is undefined.
The fracDigits parameter is optional and specifies the number of digits of fractional seconds. The default value is 0. The fracDigits parameter is ignored for format=0, 1, 2,and 4.
Examples
Print Secs2Time(DateTime,0)        // Uses "normal" format with no seconds (e.g., "1:07 PM").
Print Secs2Time(DateTime,1)        // Uses "normal" format with seconds (e.g., "1:07:28 PM").
Print Secs2Time(DateTime,2)        // Prints 13:07
Print Secs2Time(DateTime,3)        // Prints 13:07:29
Print Secs2Time(30*60*60+45*60+55,4)    // Prints 30:45
Print Secs2Time(30*60*60+45*60+55,5)    // Prints 30:45:55

 

In reply to by hegedus

I believe secs2time will provide me total seconds from 01/01/1904, thus will include the date too. I was talking about just extracting time, and no date. For example, if date-time wave has a data point as 04/29/2021 14:30:00, I only want to extract 14:30:00 and no date. This is something can be useful to study an atmospheric quantity that varies during the day, without bothering which date it happened.

Thanks

Hi,

A clarification on secs2time, the input is the number of secs and the return value is string of the time.

If I assume that your date wave is a standard numeric with date time formatting then you can use

// Get time of day from date/time value
timeOfDay = mod(dateTimeValue, 24*60*60)

so if your input wave is FullDateTime and you want just the time of day, then

JustTimeOfDay= mod(FullDateTime, 24*60*60)

since the modulus function returns the remainder after dividing by days, 24 hours * 60 minutes * 60 seconds

Andy