views:

309

answers:

3

Hi,

I have a Microsoft SQL 2005, reporting project. I want to display the Current date, time and timezone information on the page header. That is, I want to get a display as below

6/17/2009 12:25:11 PM +05:30

I added a text box to the page header. When set its expression to =Now, used the FormatDateTime function but they all either display only, date or time or date & time but not the timezone.

When I set the Format property of textbox to "o" and I got the following display 2009-06-17T12:37:36.2347500+05:30. This does have the timezone, but date and time info is not very friendly.

Is there anyway I can display the current date time and timezone info the the format (6/17/2009 12:25:11 PM +05:30) I require?

Thanks Shreedhar

+1  A: 

Please use this:

DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt K")
TheVillageIdiot
+1  A: 

use DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss tt K")

AB
even the answer by TheVillageIdiot is correct
Shreedhar
A: 

Be careful with the format you define "friendly". Since you want to display the timezone I suppose your app has to be used by people living all over the world: for most of them the format "MM/dd/yyyy" is not friendly at all.
Think of a date like "06/10/2009": for English people it's clearly the 10th of June, but for Latin people it will likely be the 6th of October.
The ISO format is not very friendly, I agree, but the informations are displayed in a hierarchical order from the greatest to the smallest. Besides almost nobody uses natively it, and this can be a plus, since everybody will have to understand what it is looking at, without making false assumptions based on his/her locale.

Turro
@Turro, while I agree with your concern regarding the friendlyness of dateformats, I wanted to display the date in mm/dd/yyyy hh:mm:ss am/pm tmezone format. I tried solutions from AB and TheVillageIdiot they both accomplish the task
Shreedhar
Ok, that's perfectly fine for me. I actually just wanted to warn you about the _possible_ (not necessary) implications of the format and didn't even try to compete with my two mates since they have been quicker than me. :)
Turro