0

I have a time field that i would like to represent on a lightswitch screen. They only offer a date time picker and viewer. Does anybody know a work around for this?

I do not want the date, just time. In my database the column is defined as time(7). Just need to get that in Lightswitch now. Help please.

I tried change my database type to varchar and use a regular textbox, however Lightswitch doesn't offer me to format the textbox (e.g. : AM/PM). If I can do that, that it would be a good workaround, however I cannot do that in Lightswitch.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Maverick1415
  • 113
  • 1
  • 12
  • 1
    *that would be a good workaround* - **NO** it would not be. Please stop storing dates and/or time as string / varchar - **right now!** Use the appropriate datatypes - that's what they're there for – marc_s Apr 10 '14 at 16:06
  • See http://stackoverflow.com/questions/7050656/time-datatype-in-visual-studio-lightswitch. – Matt Thalman Apr 10 '14 at 16:51
  • @marc_s well if lightswitch allowed me a way to do it.. then i will .. if i dont have another choice.. i will have to! – Maverick1415 Apr 10 '14 at 17:26
  • @MattThalman That is a lot of work to get a timepicker control working in LightSwitch. I could have sworn LightSwitch's target audiance was entry level dev/ end user? – HiTech Aug 21 '14 at 01:24

2 Answers2

0

For the control, I'm pretty sure you will be stuck with a Date Time Picker/Viewer unless you create a custom control that will just do time. In that case the Article linked by @MichaelWashington in the answer mentioned by @MattThalman is the way to go.

But as for display, Lightswitch certainly allows you to format it to your liking. Looking at this MSDN article: How to: Format Numbers and Dates in a LightSwitch Application. Basically you would open your table in the Data Designer and then select your Date Time field. In that field's Properties, you can enter a Format Pattern.

From the MSDN article: Reference: Number and Date Formats. A Format Pattern of "t" would result in a displayed result of: 1:45 PM.

@marc_s is correct. Use the appropriate types. Storing dates and times as strings will cause you a massive amount of headaches later on. Don't do it.

I'm not sure as to the ramifications of using a Date Time type in Lightswitch and time(7) is SQL. I would probably just change your database type to datetime or datetime2. If you don't use the date part, so be it. But it will be there later on if the requirements change.

embedded.kyle
  • 10,976
  • 5
  • 37
  • 56
0

I had the same problem and came up with this solution.

On your datetime control representing your date field, you can use JQuery on the post render event to hide the part you don't want.

myapp.AddEditEvents.FinishTime_postRender = function (element, contentItem) {

    // Hide the Date part of the Control by removing the first fieldset tag it comes to,
    $(element).find('fieldset:first').remove();

};