Is there any way to Indentify the Time if it comes 12 Hour format without AM/PM? - objective-c

I am getting date from web service in 12 hour Format like this #"2012-11-23 04:46:19.120". Is there any way to identify weather this time is AM or PM? Please guide me what should I do to get the correct result?
I am getting Dictionary in Response like this:
{
address = "22 W 46th St,\nNew York,New York,10036";
"business_name" = "Monster Sushi Midtown";
"con_res_id" = 5940;
"current_date" = "2012-11-23 04:46:19.120";
"deal_description" = "Enjoy Happy Hour with $3 Large Beers & $2 Regular Beers";
}

Thanks iosRider for your question and providing some informations.
The answer is NO.
If your database is not storing the AM / PM, cocoa cant convert it into AM or PM.
Now what you can do is :
Discard the timestamp from both the dates, store it in NSString and compare !!!

no, if the date format of the response is a 12 hours format and do not include the AM/PM value there is no way to infer it.

Related

How to get time from Date & time field in SQL? [duplicate]

In my table I have a datetime field that stores dates in this format:
YYYY/mm/dd HH:MM:SS
Now I need to retrieve via query only the time.
I have tried this
SELECT time(start_date)
FROM table
LIMIT 100
but no luck, it gives me "not an error" but no records return
Any idea?
EDIT
I solved it! The problem is that SQLite needs Times to be in a format in which if hours, minutes and seconds are less than 10 they must be represented with the zero.
For example:
H:M:S
WRONG --> 12:1:30
RIGHT --> 12:01:30
Moreover, the correct format for dates is YYYY-mm-dd and not YYYY/mm/dd.
There is a built-in function in SQLite called strftime(format,datetime) which can be used to get whatever piece of information you require from the given datetime. In your case you can use in this way:
SELECT strftime('%H:%M:%S',start_date) FROM table LIMIT 100;

Backendless filter results based on current date

I have this query
https://api.backendless.com/v1/data/abc?pageSize=100&loadRelations=cinema&sortBy=showing%20asc&where=objectId%3D%272C225111-18FC-DD4F-FF40-E227F49F5B00%27%20AND%20showing%20%3E%20%2714-June-2016%27
Thi query rightly fetches all the results after the date 14 June 2016. But I am giving a hard coded date here, Is there any way I can simply add current time/date here so that It brings all the results prior to current time? I am looking for something like
https://api.backendless.com/v1/data/abc?pageSize=100&loadRelations=cinema&sortBy=showing%20asc&where=objectId%3D%272C225111-18FC-DD4F-FF40-E227F49F5B00%27%20AND%20showing%20%3E%20%CURRENT TIME%27
I have searched alot, and even the documentation refers to hardcode dates or millisecond format only. Any help is appreciated
The easiest option is just to use the UNIX timestamp version of the date, so the string to use in your where clause would be like:
NSString *where = [NSString stringWithFormat:#"showing < %#", [[NSDate date] timeIntervalSince1970]];

VB.net checking date (year) to see if its an weird year

I'm looping through LDAP data placing some data from that into an MS SQL database. Out of the 7k+ LDAP records, a few have been causing an issue when trying to place the lastlogin into the database that has a DateTime format.
The problem is the date it has, 12/31/1600 7:00:00 PM, is not correct and causes an error of
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
The statement has been terminated.
I've been checking the date format before it inserts it into the database.
If Not IsDate(empInfo.lastLogon) Then
empInfo.lastLogon = Format(Now.AddYears(-1), "MM/dd/yyyy HH:MM:ss")
End If
But doesn't seem to catch the year of 1600 which seems to be causing that error above.
Is there any code I can use to detect those weird years and replace it with a random, legit date so it will place it into the database?
I think your problem is caused because what is a valid date in the code is not a valid date in the database, probably because the database can store an earliest date of 1753 something, whereas the code allows much earlier dates (such as the 1600 you cited).
Try adding a test for the year to your IF statement:
If Not IsDate(empInfo.lastLogon) OrElse empInfo.lastLogon.year < 2000 Then
empInfo.lastLogon = Format(Now.AddYears(-1), "MM/dd/yyyy HH:MM:ss")
End If
Instead of using a default of 1 year ago, you might want to use a marker value like 01/01/2000 00:00:00. This will let you easily identify ones which didn't have a "real" value. But I don't know your business rules, so YMMV.
For months use MM, but for minutes use mm.
I.e.; you should use MM/dd/yyyy HH:mm:ss instead of MM/dd/yyyy HH:MM:ss.
I hope it helps you.
I think you want something like this:
If Not IsDate(empInfo.lastLogon) OrElse DateTime.Parse(empInfo.lastLogon).Year < 2000 Then
empInfo.lastLogon = Format(Now.AddYears(-1), "MM/dd/yyyy HH:mm:ss")
End If

Convert a BC date to an AD

I have dates, which are prior to year 0. I need to convert them to an AD date and add 1 year more. For example I have BC 16.2.2011 and want AD 16.2.2012.
We have a 3rd side Java application, in which sometimes an error occurs; it saves the date incorrectly. In example above it should save 16.2.2012 but instead, in the DB, is -16.2.2011 (it is one "year smaller" because Oracle has no year zero - this is important).
Converting these dates is easy, but the problem is that when a saved date should be 29.2.2012 because there is no -29.2.2011. Instead of this date it saves -1.3.2011, which I can't convert easily.
Is there any way to convert the date correctly? Like get seconds from start year right from dump data in the database?
Tell us if it is something wrong with:
select to_date(to_char(your_bc_date_here,'dd.mm.YYYY'), 'dd.mm.YYYY') + 1 from dual;
This is a wrong cast because it does not considers year may be negative(correct would be syyyy)
I've tested with: your_bc_date = to_date('BC 28.2.2011', 'BC dd.mm.yyyy')

How do I convert an INT into HH:mm:ss using SSRS 2005

Ok I need to display total talk time of an agent that is coming into SRSS 2005 from SQL 2005 as an INT.
For the life of me I cannot figure out what combination of expression editing or format editing I need to use.
For the detail portion I can use: =DATEADD("s", SUM(Fields!Talk_Time.Value), CDate("00:00"))
And it will return: 1/1/0001 12:00:14 AM
Now I can use =LEFT(DATEADD("s", SUM(Fields!Talk_Time.Value), CDate("00:00")),8)
Which will return: 12:00:14
But really what I need is: 00:00:14
Please help!
Basically you are getting back 12 hour time as in 12 AM or in "hh" format, you want 24 hour time or "HH" format.
You can use the ToString() function to help you format it the way you want it...I'll put in 14 seconds in place of your SUM(Fields!Talk_Time.Value)
=DATEADD("s", 14, CDate("00:00")).ToString("HH:mm:ss")
Returns...00:00:14
Or say it's more like 3 hours (10,800 sec)...
=DATEADD("s", 10800, CDate("00:00")).ToString("HH:mm:ss")
Returns...03:00:00
That will do the trick with no LEFT or RIGHT needed.
=DATEADD("s", SUM(Fields!Talk_Time.Value), CDate("00:00")).ToString("HH:mm:ss")