Converting time

Hi I was wondering if anyone could help me out with an application I am working on. I am trying to retrieve data from a text file and show it on a second form. i am having issues converting strings to classes. when i run it i get an exception to parse the
string totake the date before putting each variable into the datetime object.
Here is my code so far:
  private void CreateEventList()
         CommnunityEvents = new List<Community_Event>();
         // call the extract Data method.
         ExtractData();
         if (CommnunityEvents.Count > 0)
            //if there are no events for the date selected display the following
            eventComboBox.Text = " -Events- ";
            descriptionTextBox.Text = "Pick an event";
         else
            //if there are no events for the date selected display the following
            eventComboBox.Text = " No Events ";
            descriptionTextBox.Text = "No events today.";
      // Create Method ExtractData
      private void ExtractData()
         CommnunityEvents.Clear();
         // load the data from the file
         List<Community_Event> tempList = new List<Community_Event>();
         //string[] fileLines = File.ReadLines(@"C:\Users\IAN\Documents\calendar.txt");
         foreach(string line in File.ReadAllLines("Calendar.txt"))
            string[] items = line.Split(",".ToCharArray());
               Community_Event newEvent = new Community_Event();
               newEvent.Day = Convert.ToInt32(items[0]);//Converting the Integer to a string.
               newEvent.Time = items[1];
               newEvent.Price = Convert.ToInt32(items[2]);//Converting the decimal to a string.
               newEvent.Event = items[3];
               newEvent.Description = items[4];
         CommnunityEvents = (from ev in tempList
                                      where ev.Day == 1
                                      select ev).ToList();

The Convert.ToInt32 methods converts the string to an int. You should use the Convert.ToDecimal to convert it to a decimal:
newEvent.Price = Convert.ToDecimal(items[2]);//Converting the decimal to a string.
Of course items[2] must contain a value that can actually be converted to a string for this to work. Alsom the Price property of the newEvent should be a decimal. Otherwise you also have the Convert.ToDouble method for example.
Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question.

Similar Messages

  • Need to convert time to GMT or UNIVERSAL CO-ORDINATED TIME

    Hi,
        I need to convert a date and time to UNIVERSAL CO-ORDINATED TIME or GMT. Is there any function module to do the same. Please do let me know.
    TIA
    Gurpreet

    Hi,
    Here is the example program to conver the time to UTC
    DATA: time_stamp TYPE timestamp,
           dat TYPE d,
           tim TYPE t,
           tz   TYPE ttzz-tzone,
           dst (1) TYPE c.
    tz = 'UTC '.     " You need to maintain the ZONE
    time_stamp = 20030309033000.
    CONVERT TIME STAMP time_stamp TIME ZONE tz
            INTO DATE dat TIME tim DAYLIGHT SAVING TIME dst.
    WRITE: /(10) dat, (8) tim, dst.
    time_stamp = 20030309043000.
    CONVERT TIME STAMP time_stamp TIME ZONE tz
            INTO DATE dat TIME tim DAYLIGHT SAVING TIME dst.
    WRITE: /(10) dat, (8) tim, dst.
    Regards
    Sudheer

  • Converting time stamp to double

    Hello,
    I am currently using the write to spreadsheet file.vi to save data.
    It looks something like this:
    I also want to add the date and time stamp into the saved data but do not know a way of converting a date and time stamp to 'double format'. When the date and time stamp is in teh double format I can easily concatenate the data stream with the 'date and time' in a 2-D array.
    Thanks,
    Nevica

    Duplicate post
    http://forums.ni.com/t5/LabVIEW/converting-time-st​amp-to-double/td-p/1181397
    Tim
    Johnson Controls
    Holland Michigan

  • How to convert time stamp to time in update rule

    Anybody know how to convert time stamp to time only?  Any FM that I can use?
    time stamp example
    20010203100201
    Result:
    10:02:01
    Thank
    Sudree

    Please search the forum

  • Error when converting time stamp in date time time zone CST  in IC

    Hi Experts,
    We have recently upgraded from CRM 5.0 to CRM 2007. We are using IC WEB Employee interaction center.
    so when agent create service ticket in interaction center and close the ticket on same day we are getting an error saying Error when converting time stamp in date time time zone CST.
    we thought there may be problem while installing SAP CRM by basis team in time zone, but we did not find any problem.
    So please advice how to resolve this issue.
    Regards,
    Teja

    Hi Teja,
    I saw a similar message, and it was resolved by adding a timezone to the user profile defaults tab in SU3. I believe the system has been configured to convert between users' timezone and the system timezone, therefore it needs to know each users' timezone.
    Regards,
    Simon.

  • Converting Time format to Decimal Value

    Dear All,
    How to convert time to decimal value for substraction of time and decimal value
    for eg l_time type tims
           l_dec type p.
    l_diff = l_time - l_dec
    Kindly let me know.
    Thanks in Advacne,
    Ranjan

    Hi,
    Try like this...
    PARAMETERS : tim TYPE tims,
                 y TYPE p.
    DATA : t TYPE string,
           t1 TYPE string,
           t2 TYPE string,
           t3 TYPE string.
    START-OF-SELECTION.
      t = tim(2).
      t  = t * 3600. " hours to second
      t1 = tim+2(2).
      t1 = t1 * 60.  " minutes to second
      t2 = tim+4(2).
      t3 = t + t1 + t2. " total time in second
      t3 = t3 - y.
    Regards
    Debarshi

  • Convert time to number and number to time

    I'm using SAP 4.0b
    I'm looking for function that converts time to number and number to time.
    Any suggestion?

    Hi,
    Can you give an example of what number you want to give to get what time and vice-versa?
    There can be a direct conversion between an integer and a time variable in ABAP.
    For example -
    data: number type i,
          time type syuzeit.
    number = 3600.
    move number to time.
    write time.
    The time will be output as "01:00:00". That is because 3600 seconds make up one hour.
    Regards,
    Anand Mandalika.

  • Help convert time

    Hi All,
    I'm trying to convert time in millisecond beginning on Jan. 1, 1970 to MMDDYY HH:MM:SS. GMT Can someone give me some direction? Thanks in advance!

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss");
    String strDate = sdf.format(new Date());You'll need to change the pattern string passed to SimpleDateFormat to match what you want.
    You will also need to set your TimeZone to GMT, as the new Date() returns the date on the client machine.
    I hope this gets you started in the right direction.

  • Fm to convert time from 12 hour to 24 hour format?

    Hi Gurus,
    Can you please tell me the Funtion module for converting time from 12 to 24 hour format and how to use that, kindly provide some test data too.
    THanks and Regards
    Sudipto

    Hi,
    You can use FM HRVE_CONVERT_TIME to convert time to 24 hour format.
    Pass B in TYPE_TIME parameter and time you wish to convert to along with AM/PM in INPUT_AM_PM parameter.
    Regards,
    Ni3

  • Converting Time Interval

    Hi all,
    I really need some help with converting time difference in days (2.02803) to DD:HH:MM:SS (2:0:40:22) format. Time difference is a number field.
    Thanks
    Kumar

    try this
    CStr (int(Truncate (DATEDIFF('n',,) /1440 ))) & ":" &
    CStr (int(Remainder(Truncate (DATEDIFF('n',,) /60 ),24))) & ":" &
    CStr (int(Remainder(DATEDIFF('n',,),60)))
    This shows the output as
    DD:HH:MM
    Regards,
    Raghavendra

  • Converting time one format to another

    Hi Friends,
    I have a small problem in converting time..
    Actually In my program i am getting time like this ' 080000 ' but that should be converted to 8.00 hrs
    if i give time is ' 085215 ' means 8 hrs 52 min 15 sec so...it should be changes to 8.52.15
    Is there any function module is change this format..pls tell me
    thanks,
    laxmi

    Hi,
    it can be acheived by writing a single write:
    Eg:
    DATA TIME TYPE T VALUE '154633'.
      WRITE (8) TIME USING EDIT MASK '__:__:__'.  "Output: 15:46:33
    if you want with dots, then replace dots by colon in write iteself...
    WRITE (8) TIME USING EDIT MASK '__.__.__'.  "Output: 15.46.33
    it will fullfill ur requirement...
    Hope it helps!!
    Regards,
    Pavan
    Edited by: vishnu Pavan on Mar 23, 2009 8:16 AM
    Edited by: vishnu Pavan on Mar 23, 2009 8:17 AM

  • Convert time from digits to words

    Hi,
    Is there a built-in or freely available actionscript function
    that would convert time from digits to words. For example, "9:30"
    becomes "half past nine"?
    Thanks!

    oops, missed the requirement for numbers as words, added that
    in:
    edit: fixed '1 minutes past' changed to '1 minute past'
    edit2:clarity with Number type on hour

  • How do I convert time lapse still images into a video in Premire Elements 13?

    I have 250 images taken at 15 second intervals that I want to convert to a video. I am not having any luck finding how to get elements to put the single pictures together. After I import the images I can play them but have not been able to shorten the time each still plays. So It is like a slide shot and not time lapse.

    Bobclarkfiber
    Please read my blog post very details how to for Time Lapse video and Premiere Elements.
    http://www.atr935.blogspot.com/2013/07/pe-time-lapse-video-basics.html
    and my less preferred way
    http://www.atr935.blogspot.com/2013/08/pe-numbered-stills-in-time-lapse-and.html
    Please review and consider. If you have questions or need clarification on any of the above, please do not
    hesitate to ask.
    Thank you.
    ATR

  • Converting TIme to a different zone time

    Hi,
    Right now, In my applicaiton a timestamp value is inserted to Database table. But as of now it inserts current system time (which ever zone application is run).
    what can I do to make to change it to timestamp of US pacific zone.
    As of now, the value below is inserted. This values needs to be changed to America los angeles time.
    java.util.Date utilDate = new java.util.Date();
    java.sql.Timestamp sqlDate = new java.sql.Timestamp(utilDate.getTime());
    sqlDate is the value which I am inserting.
    this sqlDate needs to be converted to pacific zone timestamp.
    Thanks,
    James

    You can get a Calendar instance using a TimeZone as parameter. From there it's easy.
    TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); is a good TimeZone candidate I guess.
    Edited by: Mr.E.H. on Mar 5, 2008 8:16 AM

  • Convert time in miliiseconds to date format

    I have a column in my table with datatype number(38,0) , in that column i have values in form of miliseconds since 1970 e.g 1152567973042...
    i have a requirement to convert this time in milliseconds to today's date, which i can do as
    1152567973042 / 3600 / 24 / 365 == x
    1970 + x = today's date
    is there a function in oracle supporting this, or i have to customize my requirements and write a function.
    Thanks in anticipation

    Your function will not work precisely because it does not account for leap years. You should use Oracle date math. If you add a number to an Oracle date datatype, it assumes that the number is in days. Oracle will automatically account for leap years. Try this:
    DECLARE
    mydate DATE;
    milliseconds_since_1970 NUMBER(30,7);
    BEGIN
    milliseconds_since_1970 := ?;
    mydate := TO_DATE( '01-JAN-1970', 'DD-MON-YYYY') + milliseconds_since_1970/(1000*60*60*24);
    DBMS_OUTPUT.PUT_LINE('mydate = ' || to_char( mydate, 'DD-MON-YYYY HH24:MI:SS' ) );
    END;
    This converts your milliseconds (replace ? with the number) to days and then adds the days to January 1, 1970. The result is an Oracle date datatype adjusted for leap years.
    Oracle date datatypes have hours, minutes, and seconds. Since these were not specified for 1/1/1970, they default to zero. Since milliseconds_since_1970 has 7 decimal places, it will contain fractional days which Oracle converts to hours, minutes, and seconds.
    I'm not sure what format Oracle stores date datatypes in. You have to convert them with a format string every time you use them.
    Kevin Tyson

  • How to convert Time stamp format in CR

    Dear all Expert,
    I have a question. I have a field in my CR which is date time. It show 24.03.2011 03:30:00 in the tables. But when i drop this field in my CR, it become 20,100,906,080,000.00. How to convert it to 24.03.2011 03:30:00 in CR?
    Thank You.

    Hi Alex,
    If cdatetime won't work, try the following by creating a formula . Note : replace your time with database date field i.e. date_4.
    WhilePrintingRecords;
    Stringvar date4:=totext('24.03.2011 03:30:00');
    Numbervar yr;
    Numbervar mon;
    Numbervar dt;
    numbervar hh;
    numbervar mm;
    numbervar ss;
    yr:=tonumber(mid(date4,7,4));
    mon:=tonumber(mid(date4,4,2));
    dt:=tonumber(left(date4,2));
    hh:=tonumber(mid(date4,12,2));
    mm:=tonumber(mid(date4,15,2));
    ss:=tonumber(mid(date4,18,2));
    cdatetime(yr,mon,dt,hh,mm,ss);
    Thanks,
    Sastry

Maybe you are looking for

  • How to make TM start a NEW backup

    Since January and updating to 10.5.6 (not sure if that had anything to do with it), my iMac had been freezing up and required me to manually power off and on, at first a few times a week, later increasing to several times a day. I suspected a HD fail

  • Bridge CS6 Batch Renaming

    I take pictures of a swim team and I keyword tag each image with the swimmers name.  I would like to batch rename and save in a new folder the files so they have the original filename and then the keyword name.  I don't see that as an option in the m

  • I need help its urgent.

    hi, i have fields :  S_DISCTY FOR  VBAK-ZZDISCTY1                   S_DISPRT FOR  VBAK-ZZDISPORT1 in data base tables zzdiscty1 lenght is 3 charaters. my requirememnt is at selection screen the length of these field should make itas 2 characters.how

  • Itunes is not recognizing my iphone.

    Itunes is not recognizing my iphone. when i plug my iphone in, iphoto pops up and my photos appear but nothing happens on itunes. i have a mac pro.

  • Create document number range 03 using internal number assignment in AFAB

    Hi Experts, Where i have to create number range to Depreciation Posting ? Please mentain Transaction code . I had check T Code:AS08 (No Tick is assign)  & FBN1 (Intrenal Tick is assign) I am doing T Code AFAB Folowing error coming Create document num