Converting seconds into time and date

 

 

I am trying to fix my function so that I can convert my time wave, which is in seconds, to a time and date wave (00:00:00 YYYY/MM/DD).

This is the program I have written but IGOR won't allow me to compile this and I think it's because I have the secs2date function. I am an amateur programmer so if anyone can help me fix this, that would be great!


Function time2date(time_wave)

Wave time_wave

variable i

Duplicate/o time_wave time_date_wave

For (i=0; i<(numpnts(time_wave)); i+=1)
date_wave = (secs2date(date_wave[i], -1)[6,9])

Endfor


Appendtotable time_date_wave


End

 

 

Based on your description of the problem, I think you want to use something like this:
Function time2date(time_wave)

    Wave time_wave  // numeric wave in seconds

    variable i
   
    // Make a text wave with the same number of rows as the input wave.
    Make/O/N=(DimSize(time_wave, 0))/T date_time_text_wave

    For (i=0; i<(numpnts(time_wave)); i+=1)
        date_time_text_wave = secs2time(time_wave[i], 3) + " " + secs2date(time_wave[i], -2, "/")
   
    Endfor
         
    Appendtotable date_time_text_wave
End


Note that both secs2time and secs2date assume that you are providing a wave containing the number of seconds since 1/1/1904. If your input wave doesn't use the same baseline, you will need to add an offset factor so that you get the correct date in the output wave.

If you haven't done so already, I suggest that you go through the guided tour to familiarize yourself with Igor. Select the Help->Getting Started menu item to get started. The guided tour doesn't cover this specific point, but it introduces you to important concepts you need to understand to use Igor efficiently.
If you are willing to be flexible in the sequence of your time/date output format there is an alternative using built-in conversions of numeric value waves. An example is shown in the help file found by executing
DisplayHelpTopic "Date/Time Waves"
Thank you for your helpful suggestions.

To aclight, I tried running this program you suggested but it gave me a similar error to one of my previous attempts. The date stays the same throughout the entire wave (1904/12/30) and doesn't increase by day/month as I'd like it to.
Turtle Sandwich wrote:
Thank you for your helpful suggestions.

To aclight, I tried running this program you suggested but it gave me a similar error to one of my previous attempts. The date stays the same throughout the entire wave (1904/12/30) and doesn't increase by day/month as I'd like it to.


Your original complaint was that the function you wrote would not compile. The function I provided above does compile. Since you didn't provide an example of the wave you're passing into the function, it's hard to offer advice about how to solve your problem since we can't reproduce it in the first place.
Is it possible that the real issue is that you don't understand how Igor stores date/time info? The date/time is encoded as the number of seconds since Jan 1, 1904. Those are really big numbers for recent dates so you *must* use a double precision wave. Do this:

Make/O/D/N=100 junk=3e9+1000*p
Edit junk

What you see is very large numbers. Now do this:
ModifyTable format(junk)=8

Now you see how Igor interprets those big numbers when it's told that they represent date/time data.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com