Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert NSDate to Sql Server Datetime format

I'm calling a .net web service from iPhone application that takes parameter with dateTime data type. I want to pass the Current date. I wanted to know which date format I need to use. I would appreciate your help, Thanks

NSDate *now=[NSDate date]; 
like image 639
Sarah Avatar asked Jul 13 '26 00:07

Sarah


1 Answers

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat: @"yyyy-MM-dd HH:mm:ss"];
[dateFormatter setTimeZone: [NSTimeZone timeZoneWithname:@"UTC"]];
NSString *sqlDate = [dateFormatter stringFromDate: date]; // date is your NSDate object

EDIT: Updated answer to take timezone into account. Obviously you should use the same timezone used on the original date.

like image 159
Julian Avatar answered Jul 14 '26 13:07

Julian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!