locked
Initialize sharepoint list with exact current time RRS feed

  • Question

  • I have a list in sharepoint 2007 which initializes a input field with the current date & the time is initialized with the hour after 'now' (for example: 16:01 will initialize as 17:00).

    If the current time is for example 16:01 is it possible to initialize with 16:05? (or 16:07 with 16:10, 16:28 with 16:30 etc.)

    Column type is "date and time", date and time format "date & time", default value: "Today's Date".

    Monday, July 2, 2012 4:33 PM

All replies

  • what is the code you are using to add hour? how are you doing this?

    --Cheers

    Tuesday, July 3, 2012 5:27 AM
  • Hi,

    You can use ceiling and floor method for rounding of values for time.

    Hope this URL will help you.

    http://insertalias.blogspot.in/2010/08/trimmingrounding-date-time-floors-and.html

    For further help free to post.


    Thanks, Sudhanshu Shekhar(MCTS)

    Tuesday, July 3, 2012 6:08 AM
  • what is the code you are using to add hour? how are you doing this?

    --Cheers

    I just do: create column and then use the settings from the last sentence of my post.

    As in:

    The printscreen doesn't show the default value "today's date", but that's the one i put on.

    http://3.bp.blogspot.com/-sbaJAJCToME/T2rW7qy3eUI/AAAAAAAAE8A/E6ApdUVcIf8/s1600/ColumnValidation_01.jpg

    Tuesday, July 3, 2012 2:42 PM
  • Hi,

    You can use ceiling and floor method for rounding of values for time.

    Hope this URL will help you.

    http://insertalias.blogspot.in/2010/08/trimmingrounding-date-time-floors-and.html

    For further help free to post.


    Thanks, Sudhanshu Shekhar(MCTS)

    I don't know how to use this on a sharepoint list... do I put it in a web part? content editor web part? content query web part?


    Thanks for the answer though!

    Tuesday, July 3, 2012 2:56 PM
  • Hi PeterBELMA,

    Based on your description, if the column type was set like you said, then the minute you can select by design is 00, 05, 10 etc.

    Please check it, if it’s not the issue, please provide more information about how you create the input field and set its value.

    Best Regards.

    Wednesday, July 4, 2012 5:20 AM
    Moderator
  • Hi Peter,

    Try this 

    On page Load of a simple ASP.Net web application I tried this

    On page load()

    {

              string D= DateTime.Now.ToShortTimeString();
              TextBox1.Text = D.ToString();
            }

            protected void Button1_Click(object sender, EventArgs e)
            {

                DateTime time = DateTime.Parse(TextBox1.Text);
                float minutes = time.Minute + time.Second / 60.0f;
                float rem = minutes % 5;
                if (rem != 0)
                {
                    if (rem >= 2.5f)
                    {
                        time = time.AddMinutes(5 - rem);
                    }
                    else
                    {
                        time = time.AddMinutes(-rem);
                    }
                }
                Label1.Text = time.TimeOfDay.ToString();
            }

    This code will round of time like 12:07 to 12:05 and 12:08 to 12:10 

    For exact what you want that is 12:02 to 12:05 and 12:08 to 12:10

    use this:

    On page load()

    {

              string D= DateTime.Now.ToShortTimeString();
              TextBox1.Text = D.ToString();
            }

            protected void Button1_Click(object sender, EventArgs e)
            {

                DateTime time = DateTime.Parse(TextBox1.Text);
                float minutes = time.Minute + time.Second / 60.0f;
                float rem = minutes % 5;
                if (rem != 0)
                {
                   
                        time = time.AddMinutes(5 - rem);
                }
                Label1.Text = time.TimeOfDay.ToString();
            }

    Feel free to Post for further help!

    Mark as answer if it helps


    Thanks, Sudhanshu Shekhar(MCTS)



    • Edited by sudhanshu_9 Wednesday, July 4, 2012 7:08 AM
    Wednesday, July 4, 2012 6:46 AM
  • Hi PeterBELMA,

    Based on your description, if the column type was set like you said, then the minute you can select by design is 00, 05, 10 etc.

    Please check it, if it’s not the issue, please provide more information about how you create the input field and set its value.

    Best Regards.

    Hi, I can indeed select the minute values as 00-05-10-15-... but the list is used as a shift log for shift workers.

    Now they create a new item, time is initiated as for example 14:00when created time is 13:01 and because shift workers are lazy all input made between 13:01 and 14:00 is initiated and logged as 14:00 (they don't adjust the minute value, they let it be as is).

    I'd rather have it initiated on the value closest by f.e. 13:01 > 13:05 - 13:24 > 13:25.

    Surely we can work with time "created" only, but it frequently happens that you want to log something on a time a few hours (or even days) back...and time "created" cannot be adjusted. So that's why I had to create a extra timestamp column which is adjustable.

    Thursday, July 5, 2012 1:30 PM