Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8512145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:12:06+00:00 2026-06-11T04:12:06+00:00

I am getting an output from MS SQL server in the ‘2012-08-09 00:00:00’ (without

  • 0

I am getting an output from MS SQL server in the ‘2012-08-09 00:00:00’ (without quotes) format.

However, when I write it to excel file I’m unable to write it in date format to have dd mmm yyyy formatting on excel.

As a result i tried to write in format =date(2012,08,09) as a formula to the respective cells.

But I don’t want to output it as a formula but rather the value ’09 Aug 2012′ with the data type integrity intact. How do I do this? Or is there a simpler method?

I read through the documentation but it was not clear to me, thought I would ask for clarification.

Regards.


Sorry for not being detailed enough.

I am using the PHPExcel library.

From my sql array, i use the following:

$t_year    = substr($xls_column_datas["colname"],0,4);
$t_month   = substr($xls_column_datas["colname"],5,2);
$t_day     = substr($xls_column_datas["colname"],8,2);
$t_format  = $t_year . "," . $t_month . "," . $t_day ;
$t_format  = '=date('.$t_format.')';

$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($data_column_num, $data_row_num, $t_format );
$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($data_column_num, $data_row_num)->getNumberFormat()->setFormatCode('[$-C09]d mmm yyyy;@');

in my excel output, it shows column A2 for e.g. =DATE(2012,8,9)

rather than showing up as a formula I want excel to recognize ‘2012-08-09 00:00:00’ is a date time and format it to dd mmm yyyy.

Is this getting clear? Sorry.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:12:08+00:00Added an answer on June 11, 2026 at 4:12 am

    Is your problem in getting the date from MS SQL as a date/time, or setting the Excel date?

    There is a whole section of the PHPExcel documentation that explains the use of the PHPExcel_Shared_Date::PHPToExcel($PHPDate) and PHPExcel_Shared_Date::FormattedPHPToExcel($year, $month, $day, $hours=0, $minutes=0, $seconds=0) helper methods for converting PHP dates to an Excel datetime stamp value that you set as the cell value, and then you apply a number format mask of one of the date masks such as PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2 to that cell

    Instead of

    $t_year     = substr($xls_column_datas["colname"],0,4);    
    $t_month    = substr($xls_column_datas["colname"],5,2);    
    $t_day      = substr($xls_column_datas["colname"],8,2);
    $t_format   = '=date('.$t_format.')';
    $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($data_column_num, $data_row_num, $t_format );
    $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($data_column_num, $data_row_num)->getNumberFormat()->setFormatCode('[$-C09]d mmm yyyy;@');
    

    try setting

    $t_year   = substr($xls_column_datas["colname"],0,4);
    $t_month  = substr($xls_column_datas["colname"],4,2);  // Fixed problems with offsets
    $t_day    = substr($xls_column_datas["colname"],6,2);
    $t_date   = PHPExcel_Shared_Date::FormattedPHPToExcel($t_year, $t_month, $t_day);
    $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(
        $data_column_num, $data_row_num, $t_date 
    );
    $objPHPExcel->getActiveSheet()
        ->getStyleByColumnAndRow($data_column_num, $data_row_num)
        ->getNumberFormat()->setFormatCode(
            PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX14
        );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a devil of a time getting an output value from SQL
I am trying to import data from excel to Sql Server using Import wizard.
I am trying to write an output text file from table. I am not
I'm getting unexpected output from the all.equal method in R, specifically the implementation for
I'm having trouble finding/getting any logging output from a web service. I have a
I am getting a div that is appearing in the output from calling a
So I'm connecting to SQL Server 2005 from my Rails app via the activerecord-sqlserver-adapter.
I'm trying to write this as part of stored procedure on SQL Server 2000.
I am trying to retrieving image from sql server 2005 into asp.net web page
I'm pulling some internationalized text from a MS SQL Server 2005 database. As per

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.