I am developing an application in which user schedules his date, time and event. I was wondering if there is any possible way that I can store time in hh:mm:ss AM/PM format rather than 24 hour.

  • I think my question wasn't clear enough , adding some stuff

Problem Definition : Migration from PHP-MSSQL (Windows) web service to PHP-MYSQL (Linux)

  1. Back End was written before y2k its an old program launced as an single platform , prior to me developers ported this program on the web but did not ported the DMS (database management system aka utility for data entry guys) i am not sure about the reason behind this. Old procedure to enter data , data entry guy used to log in on windows server start the application and enter data.

  2. After migration we can no longer use old DMS program hence i have to write new DMS program.

  3. I asked few question about migration from mssql to mysql before you all can have look here https://stackoverflow.com/questions/22603868/converting-porting-mssql-table-to-mysql-table

  4. Biggest problem that i have facing is data entry guys want their dms just like before not a inch less or more (cant blame them for this).

enter image description here old dms view enter image description here new dms

  1. I am trying my level best to give them old look feel and functionality back as well as wanted to reduce their work since most of the times they have to update an old entry with new dates only , before that they used to do it by deleting whore record and recreation it again.

front end view of date added: enter image description here

mssql db structure

mssql db structure

mysql db structure mysql

有帮助吗?

解决方案 3

.ToString("HH:mm") Solved all my problems for a while.

其他提示

You are probably looking for DATE_FORMAT(date,format)

%r  Time, 12-hour (hh:mm:ss followed by AM or PM)

You should store dates and times in a database as either a Date, Time or DateTime datatype (depending on what types your db provider supports (MySql reference)). Never store these as a string.

The way the user inputs the value should be determined by their culture settings on the machine:

dateTimePicker1.Format = DateTimePickerFormat.Custom
dateTimePicker1.CustomFormat = Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern

That way if they prefer 12h format, they just set that in control panel

You can get the inputted value like so:

Dim ts As TimeSpan = New TimeSpan(DateTimePicker1.Value.Hour, DateTimePicker1.Value.Minute, DateTimePicker1.Value.Second)

Storing dates and time in the database instead of string makes life a lot easier when you come to read them because you can just format the date or time in any way you wish.

You can then use the same code in your application to show that date or time in the users preferred culture. (Formatting Date and Time for a Specific Culture)

It also allows you to perform queries on the actual date or time which would not be possible (or at least very inefficient) on a string

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top