DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

extracting date and creating a new channel

Solved!
Go to solution

How do I take a date format like 1/12/2013 and create a new channel with just the month, and one with just the year ?

I want to be able to look at month over month trend on data.

0 Kudos
Message 1 of 4
(5,159 Views)

Hello Jcheese,

assuming your time channel is "Time", and all channels are in the first group:

 

Dim i

Dim oCh_source : Set oCh_source = Data.Root.ChannelGroups(1).Channels("Time")
Dim oCh_date   :   Set oCh_date = Data.Root.ChannelGroups(1).Channels.Add("Date",DataTypeFloat64)
Dim oCh_month  :  Set oCh_month = Data.Root.ChannelGroups(1).Channels.Add("Month",DataTypeFloat64)
Dim oCh_year   :   Set oCh_year = Data.Root.ChannelGroups(1).Channels.Add("Year",DataTypeFloat64)

For i = 1 To ChnLength(1)
  oCh_date(i)  = Val(Str(oCh_source(i), "#MM/DD/YYYY"))
  oCh_month(i) = Val(Str(oCh_source(i), "#MM"))
  oCh_year(i)  = Val(Str(oCh_source(i), "#YYYY"))
Next

0 Kudos
Message 2 of 4
(5,143 Views)
Solution
Accepted by topic author Jcheese

Hello Jcheese,

 

In addition to Dia791 suggestion you have to other possible ways in DIAdem 2012:

 

A) Using the VBS commands YEAR and MONTH

 

Dim i

Dim oCh_source : Set oCh_source = Data.Root.ChannelGroups(1).Channels("Time")
Dim oCh_month  : Set oCh_month = Data.Root.ChannelGroups(1).Channels.Add("Month1",DataTypeFloat64)
Dim oCh_year   : Set oCh_year = Data.Root.ChannelGroups(1).Channels.Add("Year1",DataTypeFloat64)

For i = 1 To oCh_source.Size
  oCh_month(i) = month(oCh_source(i))
  oCh_year(i)  = year(oCh_source(i))
Next

 

B) Using a DIAdem command:

 

Call Calculate ("Ch(""[1]/Month"")= RTP(Ch(""[1]/Time""), ""M"")")
Call Calculate ("Ch(""[1]/Year"")= RTP(Ch(""[1]/Time""), ""Y"")")

 

Greetings

Walter

 

 

0 Kudos
Message 3 of 4
(5,133 Views)

worked thanks

0 Kudos
Message 4 of 4
(5,121 Views)